[英]Filtering a list in different activities
I have an app where a main activity generates a list, and in the main activity there are many tabs that filter the list and lists a subset of the entire list in a customized ListView with checkboxes. 我有一个应用程序,其中主要活动会生成一个列表,并且在主要活动中有许多选项卡可以过滤列表并在带有复选框的自定义ListView中列出整个列表的子集。
I have adapters in each of the tabs, and have threads running in the various onCreate()s that filter the main list and add the relevant subset into its own adapter. 我在每个选项卡中都有适配器,并在各种onCreate()中运行线程,这些线程过滤主列表并将相关子集添加到其自己的适配器中。 I'm saving the checkbox status into a SharedPreferences everytime the use checks a box.
每次使用复选框时,我都会将复选框状态保存到SharedPreferences中。
I'm having a problem synchronizing the checkboxes among the various ListActivities. 我在同步各个ListActivities中的复选框时遇到问题。 When I check a box in 1 ListActivity and switch to another tab, it doesn't update there.
当我在1 ListActivity中选中一个框并切换到另一个选项卡时,它不会在那里更新。 Only when I exit the app and restart it does the main activity re-generate the list, read the SharedPreferences and update all the checkboxes.
仅当我退出该应用程序并重新启动它时,主活动才会重新生成该列表,读取SharedPreferences并更新所有复选框。
How do I have this done instantaneously so that the various ListActivities of the various tabs are always synchronized? 我如何立即完成此操作,以便始终使各个选项卡的各个ListActivity同步?
Thanks. 谢谢。
I would rather suggest you use filters on the adapters (ie implementing your own filters that read from the checkbox selections). 我宁愿建议您在适配器上使用过滤器(即实现自己的从复选框选择中读取的过滤器)。 Having so many threads is: a) confusing for the programmer;
有这么多线程是:a)程序员感到困惑; b) a source of synchronization issues.
b)同步问题的来源。 Every ArrayAdapter implements Filterable interface and you can override the method getFilter() to return a filter of your own.
每个ArrayAdapter都实现Filterable接口,您可以重写getFilter()方法以返回自己的过滤器。 In this filter you can filter out the elements to what you need.
在此过滤器中,您可以根据需要过滤出元素。 I think this post should help you: How to write a custom filter for ListView with ArrayAdapter .
我认为这篇文章应该对您有所帮助: 如何使用ArrayAdapter为ListView编写自定义过滤器 。 You will probably need to read the settings in each of the filters you implement.
您可能需要阅读实现的每个过滤器中的设置。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.