How to create a ListView filter with SimpleCursorAdapter on Android

I will make a filter for a list from am SimpleCursorAdapter. I see a toast following my example, but nothing happens to the filter. I found an example with setFilterQueryProvider. But I do not know to implement this. Here's my code:

    Cursor entryCursor = mDatabase.query(
            "entrys",
            new String[] {
                    "_id",
                    "name",
                    "address"
            },
            null, null, null, null, null);
    startManagingCursor(entryCursor);

    final SimpleCursorAdapter entryAdapter =
        new SimpleCursorAdapter(this,
                android.R.layout.simple_list_item_2,
                entryCursor,
                new String [] {"name",
                               "address"},
                new int[] { android.R.id.text1,
                            android.R.id.text2}
                );

    setListAdapter(entryAdapter);

    final ListView mList = (ListView) findViewById(android.R.id.list);
    mList.setAdapter(entryAdapter);

    final EditText et_search = (EditText) findViewById(R.id.listview_search);
    et_search.addTextChangedListener(new TextWatcher() {
        public void afterTextChanged(Editable s) {
            // Abstract Method of TextWatcher Interface.
        }
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {
            // Abstract Method of TextWatcher Interface.
        }
        public void onTextChanged(CharSequence s, int start, int before, int count) {
            // Abstract Method of TextWatcher Interface.
            entryAdapter.getFilter().filter(s.toString());
            Toast.makeText(getApplicationContext(), "Text changed", Toast.LENGTH_SHORT).show();
        }
    });

      

+3
android search listview simplecursoradapter


source to share


No one has answered this question yet

Check out similar questions:

3606
Close / hide Android soft keyboard
3295
Why is the Android emulator so slow? How can we speed up the development of an Android emulator?
3288
Correct use cases for Android UserManager.isUserAGoat ()?
2609
Is there a unique identifier for an Android device?
2510
How to persist android activity state by persisting instance state?
2097
Is there a way to run Python on Android?
1858
"Debug certificate expired" error in Android Eclipse plugins
1844
What is "Context" on Android?
1832
Lazy loading images in ListView
0
Search ListView when class extends ListActivity



All Articles
Loading...
X
Show
Funny
Dev
Pics