I have implemented two fragments with ActionBar tabs. I am using Sherlock fragments. When I start a fragment I create a searchview on the action bar.
The problem is: When I search something on the first fragment and without closing the searchview or deleting the text, I move to the next fragment, I get a collapsed searchview, which is fine. But when I again get back to my first fragment, I see a list sorted like before but the searchview is collapsed. The only way to get back the original list is to click the searchview once and closing it.
How do I reset the searchview on the first fragment when I move to second fragment or how can keep the searchview open when I come to the first fragment?
Any one of the solutions will do.
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
>
<item android:id="@+id/action_search"
android:title="search"
android:icon="@drawable/search"
android:orderInCategory="100"
android:showAsAction="always|collapseActionView"
android:actionViewClass="com.actionbarsherlock.widget.SearchView" />
</menu>
This is how I am inflating in the fragment
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater)
{
super.onCreateOptionsMenu(menu, inflater);
inflater.inflate(R.menu.main, menu);
SearchView sv = (SearchView)getActivity().findViewById(R.id.action_search);
sv.setOnQueryTextListener(new OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
//...
return false;
}
@Override
public boolean onQueryTextChange(String newText) {
bindingData.resetData();
bindingData.getFilter().filter(newText.toString());
return false;
}
});
}