ListView过滤无效

时间:2014-10-18 20:18:36

标签: android listview

我在android中创建了一个列表视图,并在列表上方添加了编辑文本,当用户输入文本时,列表将根据用户输入进行过滤但不工作: enter image description here

            @Override
        public void onTextChanged(CharSequence arg0, int arg1, int arg2, int arg3) {
            // TODO Auto-generated method stub

        }


        @Override
        public void beforeTextChanged(CharSequence arg0, int arg1, int arg2,
                                      int arg3) {
            // TODO Auto-generated method stub

        }


        @Override
        public void afterTextChanged(Editable arg0) {
            MainActivity.this.myadpt.getFilter().filter(arg0);

        }
    });

1 个答案:

答案 0 :(得分:0)

试试这个:

adapter = new ListViewAdapter(this, arraylist);
list.setAdapter(adapter);
editsearch = (EditText) findViewById(R.id.search);

editsearch.addTextChangedListener(new TextWatcher() {
    public void afterTextChanged(Editable arg0) {
        String text = editsearch.getText().toString().toLowerCase(Locale.getDefault());
        adapter.filter(text);
    }
});