Okay ... So that's how I did it.
In principle, the data obtained in two fragments was not just a List<String> , but they were models, namely. Cinema and region, which contained details other than names, including location, rating, etc.
So, firstly, I created the ISearchable interface
public Interface ISearchable { // This contains the Search Text. An ISearchable item is included // in search results if query is contained in the String returned by this method public String getSearchText(); //This is meant to return the String that must be displayed if this item is in search results public String getDisplayText(); //This is meant to handle onClick of this searchableItem public void handleOnClick(); }
Both Cinema and Region models are implemented by ISearchable .
After that, I used the singleton DataManager class, in which I supported the List<ISearchable> currentSearchList .
public class DataManager { .....<singleton implementation>.... List<ISearchable> currentSearchList; public void setSearchList(List<ISearchable> searchList) { this.currentSearchList = searchList; } public List<ISearchable> getSearchList() { return this.currentSearchList; } }
Therefore, whenever a fragment (Fragment_A or Fragment_B) is loaded, it updates this currentSearchList , so when SearchableActivity searches, all it needs to do is DataManager.getInstance().getSearchList() , and then use this list to filter list of related items.
This is how I dealt with the problem of having lists in Activity other than SearchableActivity with which to search.
I understand that this may not be the best solution, so I look forward to suggestions and criticisms and use this to come up with a better solution.
unrealsoul007
source share