asmgx asmgx - 2 years ago 108
Android Question

Android: filter ListView without the adapter

I have a ListView that gets filled by SimpleAdapter, this adapter is local variable inside the procedure that fills the ListView.

Now, I want to filter the ListView, but I have no access to the adapter in the EditText events

is there a way to do that?

I tried MyListView.getAdapter().getFilter().Filter("some text");

but that gives error as getFilter does not exist for MyListView.getAdapter()

How can I fix this?

Answer Source

Declare adapter as global, setting adapter as global will let you filter it:

 YourActivity.this.adapter.getFilter().filter("some text");

Did you try this?, it should works:

 Adapter adapter= MyListView.getAdapter();
 adapter.getFilter().filter("some text");

Too you can post your code to check what are you doing wrong, if you're using a custom adapter you have to implement the getFilter method

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download