Android Listview based on SimpleAdapter Includes Image Descriptions When Searching Using Textwatcher

旧巷老猫 提交于 2019-12-13 04:25:52

问题


I have an android ListView hooked up to a Simpleadapter. It outputs specific static images as icons on the listview depending on text content of some elements as well as some text titles and sub-titles for those element.

I also have setup a textwatcher for an edittextview to filter and do autosearching.

The searching within the listview runs okay. However, I have noticed that the textwatcher includes the text content element(now converted into images) in the listview. So it appears that it is outputting some incorrect rows in the listview as the user only sees the titles/sub-titles and not the text content behind the image icons.

Is there a better way of filtering the listview which would exclude the original text behind the image icons?


回答1:


Here's the code I end up doing (thanks @Luksprog):

public void afterTextChanged(Editable s) {
    if(s.length()>0){
        int count = viewListAdapter.getCount();
        if(count > 0){
            hashMapListForListViewcopy.clear();
            for (int i = 0; i < count; i++) {
                Map temp = (Map) viewListAdapter.getItem(i);
                String txtOfferName = temp.get("txtOfferName").toString();
                HashMap<String, String> entitiesHashMap;
                entitiesHashMap = new HashMap<String, String>();
                if (txtOfferName.toLowerCase().contains(s.toString().toLowerCase())) {
                    System.out.println("Found a match!");
                    Log.v("txtOfferName", txtOfferName);
                    Log.v("viewListAdapter.getItem(i)","" + viewListAdapter.getItem(i));
                    entitiesHashMap = (HashMap<String, String>) viewListAdapter.getItem(i);
                    hashMapListForListViewcopy.add(entitiesHashMap);
                }
            }
        }   
        viewListAdaptercopy.notifyDataSetChanged();
    }   


来源:https://stackoverflow.com/questions/13448691/android-listview-based-on-simpleadapter-includes-image-descriptions-when-searchi

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!