问题
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