我有一个android ListView连接到了一个简单的适配器。它将特定的静态图像输出为列表视图上的图标,这取决于某些元素的文本内容,以及这些元素的一些文本标题和副标题。
我还为edittextview设置了一个文本监视器,用于过滤和自动搜索。
列表视图中的搜索运行正常。但是,我注意到textwatcher在listview中包含了文本内容元素(现在转换为图像)。因此,它似乎在列表视图中输出了一些不正确的行,因为用户只看到标题/副标题,而没有看到图像图标后面的文本内容。
有没有更好的方法来过滤列表视图,将图片图标后面的原始文本排除在外?
发布于 2012-11-20 07:34:53
下面是我最终要做的代码(感谢@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
复制相似问题