Answer the question
In order to leave comments, you need to log in
How to implement search in action bar via SearchManager with result on a separate page?
How to implement search in action bar via SearchManager with result on a separate page?
Answer the question
In order to leave comments, you need to log in
Working example:
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.fragment_expenses_menu, menu);
// Associate searchable configuration with the SearchView
SearchManager searchManager = (SearchManager) getActivity().getSystemService(Context.SEARCH_SERVICE);
SearchView searchView = (SearchView) menu.findItem(R.id.menu_search).getActionView();
searchView.setSearchableInfo(searchManager.getSearchableInfo(getActivity().getComponentName()));
searchView.setOnQueryTextListener(new SearchView.OnQueryTextListener() {
@Override
public boolean onQueryTextSubmit(String query) {
// String search_query for external using
AddData.EXP_SEARCH = query;
Intent intent = new Intent(getContext(), ActivityExpFromSearch.class);
intent.setAction(Intent.ACTION_SEARCH);
getContext().startActivity(intent);
return true;
}
@Override
public boolean onQueryTextChange(String newText) {
return false;
}
});
super.onCreateOptionsMenu(menu, inflater);
}
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question