在listview上搜索(activity extends ListActivity) [英] Search on listview (activity extends ListActivity)

查看:148
本文介绍了在listview上搜索(activity extends ListActivity)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的活动中扩展 ListActivity 并绑定 ListView 。应用过滤器到列表视图。当使用emulater时,过滤器工作正常,因为我有我的笔记本电脑的键盘。但是当我想在android上过滤数据时,问题就出现了,因为它没有向我显示键盘。代码如下。

  String [] Customers = {Alester,Lee,Broad,James }; 
setListAdapter(new ArrayAdapter< String>(this,R.layout.list_item,Customers));

ListView lv = getListView();
lv.setTextFilterEnabled(true);


解决方案

把EditText放在某个地方, ,然后添加一个TextWatcher,如:
$ b $ pre $ TextWatcher filterTextWatcher = new TextWatcher(){

public void afterTextChanged (可编辑的){
}

public void beforeTextChanged(CharSequence s,int start,int count,int after){
}

public void onTextChanged(CharSequence s,int start,int before,int count){
_myAdapter.getFilter()。filter(s);
}
};
_filterText =(EditText)findViewById(R.id.search_box);
_filterText.addTextChangedListener(filterTextWatcher);


i extend ListActivity and bind ListView in my activity. applied filter to listview. the filter is working fine when use emulater, because i have keyboard of my laptop. but the problem arises when i want to filter data on android because it does not display keyboard to me. code is give below.

String[] Customers = {"Alester","Lee","Broad","James"};
setListAdapter(new ArrayAdapter<String>(this, R.layout.list_item, Customers));

  ListView lv = getListView();
  lv.setTextFilterEnabled(true); 

解决方案

Put an EditText somewhere, like on top of your listView, then add a TextWatcher like :

    TextWatcher filterTextWatcher = new TextWatcher() {

        public void afterTextChanged(Editable s) {
        }

        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
        }

        public void onTextChanged(CharSequence s, int start, int before, int count) {
            _myAdapter.getFilter().filter(s);
        }
    };
    _filterText = (EditText) findViewById(R.id.search_box);
    _filterText.addTextChangedListener(filterTextWatcher);

这篇关于在listview上搜索(activity extends ListActivity)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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