Android:从下拉菜单中选择ListView过滤或复选框 [英] Android: ListView filtering from a dropdown menu OR checkboxes

查看:308
本文介绍了Android:从下拉菜单中选择ListView过滤或复选框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在浏览这些和其他论坛,我没有能够找到我正面对的这个问题的指南。


$ b $我有一个Android课程,我决定开始自己的应用程序,一切顺利,直到我达到这一点:我有一个自定义列表视图与几个项目。现在我想要在列表视图或几个复选框之前添加一个下拉菜单,以便用户可以根据他的选择过滤所述项目。



每个教程阅读关于通过编辑文本字段和用户输入过滤列表视图的谈话,但是我希望用户点击一个按钮并运行过滤器。



有没有人在这里得到教程/指导如何做到这一点?



谢谢你的时间欢呼!
Yours,
/ D〜

解决方案

回答自己,因为我设法做到这一点: / p>

许多互联网教程显示,只需让您的自定义适配器实现Filterable,然后创建一个满足您的条件的自定义过滤器 - 有很多互联网教程,但我可以如果有人需要,请附上代码。



完成之后,您需要做的就是从button / spinner调用:adapter.getFilter()。filter(yourControlString)项目。
yourControlString将基本上告诉您的自定义过滤器您想要显示什么和不想要什么 - 您必须在CustomFilter上进行自定义。再次,这听起来比真正的更难听。


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~

解决方案

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.

这篇关于Android:从下拉菜单中选择ListView过滤或复选框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆