从常规列表视图中的两个文本视图中过滤

时间:2016-11-15 10:19:52

标签: android listview filter simplecursoradapter addtextchangedlistener

我有一个带有 SimpleCursorAdapter 的常规列表视图和两个textview,我想只过滤我的一个textview

我该怎么做?

   EditText e ;

@Override
protected void onCreate(Bundle savedInstanceState)
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_search_activity);

    e = (EditText) findViewById(R.id.edit);

    DataBaseH data = new DataBaseH(this);
    SQLiteDatabase db = data.getReadableDatabase();
    String ret = "";

    Cursor C = db.rawQuery("select * from Album ", null);

    final SimpleCursorAdapter adapter = new SimpleCursorAdapter(this, R.layout.item, C, new String[]{"Title", "country"}, new int[]{R.id.t, R.id.t2}, 0);
    ListView list = (ListView) findViewById(R.id.list);
    list.setAdapter(adapter);

    e.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count)
        {
            adapter.getFilter().filter(s.toString());

            // this doesn't work 
        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });
}

只想过滤标题。

我可以同时过滤标题和国家/地区吗?

0 个答案:

没有答案