Android:ListView制作搜索过滤器
有没有办法在使用 BaseAdapter 而不是 ArrayAdapter 创建的自定义列表视图上创建搜索过滤器,因为我只遇到过在自定义列表视图中使用 ArrayAdapter 的方法。以下是我遇到的使用数组制作过滤器适配器
Is there a way to create a search filter over my custom list view which created using BaseAdapter rather than ArrayAdapter, because I have only come across methods that are using ArrayAdapters in there Custom List Views. Follwing is what I have come acrossMaking a filter using Array Adapter
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
如果您使用 List 集合,则扩展 ArrayAdapter - 它是 BaseAdapter 的子类。
覆盖 getView 方法(在您的情况下,只需复制旧的 getView 代码并进行少量修改)。
覆盖集合和集合中对象的 toString:
If you're using List collection then extend ArrayAdapter - it's subclass of BaseAdapter.
Override getView method (In your case just copy your old getView code with little modifications).
Override toString of object that is in your collection and set:
以下是使用基本适配器创建的列表视图的示例。
我搜索了很多,但没有得到任何令人满意的解决方案。因此我想把它放出来,以便将来可以帮助其他人。
这是history_container.xml的代码
这是history_list_view.xml的代码
这是history_schedule.xml的代码
抱歉,我不是能够以正确的格式放置代码。似乎有些事情发生了变化,因为不再有标签,这很好。但为了用户方便,使用选项卡也是一个好主意。
也许是我的错,我无法以正确的格式发布。而且似乎我们无法发布 xml 文件内容。所以,想想布局是如何设计的。
活动代码是:-
Here is an example for list view created using base adapter.
I searched a lot but didn't get any satisfactorily solution.Hence I thought to put it up so that in future it might help others.
Here is the code of history_container.xml
Here is the code of history_list_view.xml
Here is the code of history_schedule.xml
Sorry, I am not being able to put the code in correct format.Seems something has changed as there is no tag anymore which was nice.But for user convenience this is also a good idea to have tab.
Maybe it is my fault that I'm not being able to post in correct format.And seems like we cannot post xml file content..So, think how the layout would have designed.
The activity code is :-
ArrayAdapter 是 BaseAdapter 的子类。
ArrayAdapter 的源代码位于此处。看看它..
这应该可以解决您的问题。
ArrayAdapter is a child class of BaseAdapter.
Source code for ArrayAdapter is here. Take a look at it..
This should solve your problem.
这是一个例子。编辑并使用您需要的内容。
}
Here is an example . Edit and use what you need.
}