Trying to include a searchview in actionbar. For this, I have done the following:
Created MenuSearch.xml in the menu folder as given below:
i solved this issue i wants to share my answer for searchView NullPointerException
we need to remove below method from Main Activity
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
return true;
and use inside fragment in OnActivityCreated setHasOptionsMenu(true)
and Override methods
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
inflater.inflate(R.menu.menu, menu);
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
// handle item selection
switch (item.getItemId()) {
case R.id.action_search:
// onCall(); //your logic
return true;
default:
return super.onOptionsItemSelected(item);
}
}