I have a simple activity that contains a tab for switching two fragments. These two fragments are both a list and implement a search to make a search possible within the list. Searchview is always displayed in the action bar above the tab.
The problem is that the input of searchview isnt reset after switching the tab (switching to another fragment). Therefore, the second fragment reads the input data from the search and accordingly filters the corresponding list, which actually reads the input entered when I was still in the fragment.
I want searchview to be a separate search for both snippets. Is there any way to achieve this?
Here is my code:
activity
public class ActivityMainApp extends Activity implements ActionBar.TabListener { private FragmentManager fragmentManager = getFragmentManager(); @Override public void onCreate(Bundle icicle) { super.onCreate(icicle); setContentView(R.layout.mainapp); ActionBar actionBar = getActionBar(); actionBar.setNavigationMode(ActionBar.NAVIGATION_MODE_TABS);
Fragment one
public class FragRelaties extends ListFragment implements SearchView.OnQueryTextListener { private LayoutInflater inflater; private ModelRelatie modelRelatie; private AdapterRelatie relatieAdapter; public ArrayList<Relatie> relaties; public View onCreateView(final LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { this.inflater = inflater; Activity activity = getActivity(); final Context context = activity.getApplicationContext(); setHasOptionsMenu(true); new AsyncTask<Void, Void, ArrayList<Relatie>>(){ protected ArrayList<Relatie> doInBackground(Void... params) {
Fragment 2
public class FragTaken extends ListFragment implements SearchView.OnQueryTextListener { private LayoutInflater inflater; private AdapterTaak adapterTaak; private ModelTaken modelTaken; public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) { this.inflater = inflater; Activity activity = getActivity(); final Context context = activity.getApplicationContext(); setHasOptionsMenu(true); this.modelTaken = ModelTaken.instantiate(context); ArrayList<Taak> taken = modelTaken.getTaken();
Both fragments are almost identical, except for the search part.
source share