Android: ListView filtering from a dropdown menu O

2019-09-08 05:07发布

问题:

I've been browsing these and other "forums" for quite a bit and I've not been able to find a "guide" to this issue I'm facing.

I've had an Android course and I decided to start working on my own app, everything was going smooth until I got to this point: I got a custom listview with several items. Now I want to have either a dropdown menu just above the listview or a few checkboxes so that the user can filter said items according to his selection.

Every tutorial I've read talks about filtering the listview thru an edittext field and the user input, but I want the user to click a button and the filter run.

Has anyone out here got a tutorial/guideline on how can I do this?

Thanks and cheers for your time! Yours, /D~

回答1:

Answering myself as I've managed to do this:

As many internet tutorials show, just make your custom adapter implement Filterable and then create a custom Filter that satisfies your criteria - there's plenty of internet tutorials for this, but I could prolly attach the code if someone needs it.

After that's done, all you need to do is call: adapter.getFilter().filter(yourControlString) from the button/spinner item. yourControlString will basically tell your custom Filter what do you want to display and what you don't want to - you've to customize that on your CustomFilter. Again, this sounds harder than what it really is.