Skip to content
This repository was archived by the owner on Apr 19, 2018. It is now read-only.
This repository was archived by the owner on Apr 19, 2018. It is now read-only.

SearchView not working in multiple fragments #1075

Description

@bhavikmandalia

I have one sherlock fragment activity from which i calling the six fragments inside viewpager.

Now i want to manipulate the sherlock action bar depends on the selected tab.

So for the first 3 tab i want to show the searchview and overflow menu icon.

For that what i have tried so far ::

I am in great need of you as i am stuck in this issue from the last 4 days.

So,here is the thing....

I have one sherlock fragment activity from which i calling the six fragments inside viewpager.

Now i want to manipulate the sherlock action bar depends on the selected tab.

So for the first 3 tab i want to show the searchview and overflow menu icon.

For that what i have tried so far ::

  1. Called the setHasOptionsMenu(true); in every fragment.
  2. Added the onCreateOptionsMenu() in every fragment. and

then i have achieved what i want.

Now i want that onClick of the searchview it should get expanded and collapse when pressed the back. So to achieve that i have added this in my first 3 fragment and also implement the puru's logic .(Create the onPrepareOptionMenu() in every fragment and add the onQueryTextChange(""); method).

@Override
public void onCreate(Bundle savedInstanceState) 
{
   super.onCreate(savedInstanceState);
   getActivity().supportInvalidateOptionsMenu();
   setHasOptionsMenu(true);
}

Fragment Code ::

@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) 
{
    super.onCreateOptionsMenu(menu, inflater);

    inflater.inflate(R.menu.menu, menu);
    MenuItem searchItem = menu.findItem(R.id.menu_item_search);
    SearchView searchView = (SearchView) searchItem.getActionView();
    searchView.setQueryHint("Search for Products");
    searchView.setOnQueryTextListener(this);
    searchView.setIconifiedByDefault(false);
   }
@Override
 public void onPrepareOptionsMenu(Menu menu) 
 {
    super.onPrepareOptionsMenu(menu);
    onQueryTextChange("");
 }
  @Override
 public boolean onQueryTextSubmit(String query) 
 {
    return true;
}

@Override
public boolean onQueryTextChange(String newText)
{
    return false;
}

menu.xml

Problem :: (on Pre-HoneyComb Device)

Now when i click of the first fragment's searchview,it not get expanded,but works well for fragment 2 and fragment 3.

Steps ::

1)go to directly fragment 1,click on searchview,not expanding
2)go to directly on fragment 2 tab(not clicking onsearchview in second fragment),back to fragment 1,searchview expanding
3)go to directly on fragment 3 tab(not clicking onsearchview in third fragment),back to fragment 1,searchview expanding

Is there any issue related to the focus of searchview? or am i calling the supportInvalidateOptionsMenu() in some unusual way?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions