简体   繁体   中英

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.

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. I'm saving the checkbox status into a SharedPreferences everytime the use checks a box.

I'm having a problem synchronizing the checkboxes among the various ListActivities. When I check a box in 1 ListActivity and switch to another tab, it doesn't update there. 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.

How do I have this done instantaneously so that the various ListActivities of the various tabs are always synchronized?

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; b) a source of synchronization issues. Every ArrayAdapter implements Filterable interface and you can override the method getFilter() to return a filter of your own. 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 . You will probably need to read the settings in each of the filters you implement.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM