使用自定义适配器搜索列表视图

时间:2012-05-19 12:23:30

标签: android android-listview android-adapter

我的应用有一个带有自定义适配器的twoline ListView 。我想用EditText的输入过滤listview内容。怎么可能?

lv.setAdapter(new MyCustomBaseAdapter(getActivity(),recordObjects));
//recordObjects is an ArrayList of objects 

3 个答案:

答案 0 :(得分:1)

您必须设置TextWatcher to your EditText

然后使用动态数组过滤您的数据...

答案 1 :(得分:0)

使用addTextChangedListener方法向TextWatcher添加EditText。然后,在onTextChanged的实施中,根据需要在ListView的适配器中添加或删除项目。

答案 2 :(得分:0)

这是你想要的那种吗?

ListView lv = getListView();
            /* Gets a ListView */
            lv.setTextFilterEnabled(true);

            /* sorts the listview */
            ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                    getApplicationContext(),
                    android.R.layout.simple_list_item_1,
                    result.getheadlines());
            setListAdapter(adapter);
            /*
             * gets the lisadapter from the XML and sets it equal to
             * whatever result is
             */
相关问题