简体   繁体   中英

Finding string in a HashMap in search

I am implementing search for list. I am comparing data with the array list that contains HashMap s. How do I get a String out of it?

Here is my code...

ArrayList<HashMap<String, String>> CList;

etSearch.addTextChangedListener(new TextWatcher() {
            @Override
            public void onTextChanged(CharSequence s, int start, int before,
                    int count) {
            }

            @Override
            public void beforeTextChanged(CharSequence s, int start, int count,
                    int after) {
            }

            @Override
            public void afterTextChanged(Editable theWatchedText) {

                ArrayList<HashMap<String, String>> type_name_filter = new ArrayList<HashMap<String, String>>();

                String text = theWatchedText.toString();

                for (int i = 0; i < CList.size(); i++) {

                    if (CList.get(i)).containsKey(text.toLowerCase())) {

                        type_name_filter.add(CList.get(i));

                    }
                }

                listUpdate(type_name_filter);
            }
        });

My Clist Values are

String value1 = c.getString("Value1");
                        String userid = c.getString("UserId");
                        HashMap<String, String> map = new HashMap<String, String>();

                        map.put(TAG_Value, value1);
                        map.put(TAG_UserID, userid);
                        CList.add(map);

HashMap has no function contains . The HashMap only has methods containsKey() or containsValue()

Change:

if ((CList.get(i)).contains(text.toLowerCase())) {

To:

if ((CList.get(i)).containsKey(text.toLowerCase())) {

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM