I've got settings button at the right of my actionbar.
main.xml
from rsc/menu
:
<item
android:id="@+id/action_settings"
android:icon="@drawable/settings"
android:orderInCategory="1"
android:showAsAction="ifRoom"
android:title="Settings" />
<item
android:id="@+id/action_help"
android:orderInCategory="2"
android:showAsAction="withText"
android:title="Help" />
I want menu with other items opens after pressing this button in actionbar.
So I've added getActivity().openOptionsMenu()
to my fragment in onOptionsItemSelected()
function:
@Override
public void onCreateOptionsMenu(Menu menu, MenuInflater inflater) {
menu.clear();
inflater.inflate(R.menu.main, menu);
super.onCreateOptionsMenu(menu, inflater);
}
public boolean onOptionsItemSelected( MenuItem item) {
switch (item.getItemId()) {
case R.id.action_help:{
//make help activity
}
return true;
case R.id.action_settings:{
getActivity().openOptionsMenu();
}
return true;
default:
return super.onOptionsItemSelected(item);
}
}
As I understood we can't use openOptionsMenu()
in onCreateOptionsMenu()
But how to solve this issue by another way?