基于Android的SimpleAdapter列表视图包括图像说明搜索时使用Textwatcher [英] Android Listview based on SimpleAdapter Includes Image Descriptions When Searching Using Textwatcher

查看:232
本文介绍了基于Android的SimpleAdapter列表视图包括图像说明搜索时使用Textwatcher的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经迷上了一个Simpleadapter一个Android的ListView。它输出特定的静态图像,这取决于一些因素,以及一些文本标题和副标题为那些元素的文字内容在列表视图的图标。

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.

我也有设置一个edittextview一个textwatcher过滤并做autosearching。

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

在列表视图中的搜索运行正常。不过,我已经注意到,textwatcher包括列表视图的文本内容元素(现转换成图像)。这样看来,它在列表视图输出一些不正确的行作为用户只看到标题/子标题,而不是图像图标后面的文本内容。

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?

推荐答案

这里的code我最终会做(感谢@Luksprog):

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();
    }   

这篇关于基于Android的SimpleAdapter列表视图包括图像说明搜索时使用Textwatcher的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆