I have a main activity which has 2 fragments. The main activity has a SearchView
in the action bar. Both the fragments have a list of large number of strings, List<String>
.
The flow is:
User enters Fragment I --> Selects a string (lets say Selection1) --> Based on Selection1 a list of strings is populated in the second fragment --> Here the user selects a second String ---> Processing based on these two strings.
Now since both the fragments contain a large number of strings, the user enters a query in the SearchView
, which filters the list and reduces it to a smaller list displayed in the SearchableActivity
.
Now the problem is how does the SearchableActivity
get access to these two List<String>
to filter them based on the query and display a reduced list to the user.
Currently what I have done is overridden onSearchRequested
and pass the data as
@Override
public boolean onSearchRequested()
{
Bundle appData = new Bundle();
appData.putString(FRAGMENT_ID, "Fragment_A");
appData.putStringArrayList(SEARCH_LIST, searchList);
startSearch(null, false, appData, false);
return true;
}
Is there a better way or standard way by which this problem can be handled i.e. an implementation that allows data to be based from my MainActivity
to SearchableActivity
?
Edit: Adding code. Showing how data is set in the Fragment
. onDataReceived
is called from the HttpManager
which receives the data.
@Override
public void onDataReceived(String type,final Object object)
{
switch(type)
{
case PopItConstants.UPDATE_LIST:
getActivity().runOnUiThread(new Runnable() {
@Override
public void run()
{
updateCinemaList((List<String>) object);
}
});
break;
}
}
public void updateDataList(List<String> data)
{
this.dataList = data;
spinner.setVisibility(View.GONE);
mAdapter.updateList(dataList);
}