If you want to change the options menu at any time after creating it, you must override the onPrepareOptionsMenu () method.
public boolean onPrepareOptionsMenu (Menu menu) { menu.clear(); if (CASE_1 == 0) { CASE_1 = 1; getMenuInflater().inflate(R.menu.secondmenu, menu); } else { CASE_1 = 0; getMenuInflater().inflate(R.menu.firstmenu, menu); } return super.onPrepareOptionsMenu(menu); }
where CASE_1 refers to the menu that you want to display depending on your requirement.
Shankar agarwal
source share