I am trying to display a menu item named “share” by clicking the menu button.
now i need to create a submenu item for this share menu item.
The sub menu item should be visible when the share menu item is clicked alternatively (when clicked first time becomes visible next time invisible and so on.).
I found few solutions which are displaying the sub menuitems but those are being displayed along with the menu item.
This is my code for creating menus
public boolean onCreateOptionsMenu(Menu m) {
m.add(1,1,0,"one").setIcon(R.drawable.icon);
m.add(1,2,0,"two").setIcon(R.drawable.icon);
m.add(1,3,0,"three").setIcon(R.drawable.icon);
m.add(1,4,0,"four").setIcon(R.drawable.icon);
m.getItem(0).setVisible(false);
m.getItem(1).setVisible(false);
return true;
}
and my onPrepareOptionsMenu()
public boolean onPrepareOptionsMenu(Menu m) {
if(isvisible)
{
isvisible = false;
m.getItem(0).setVisible(true);
m.getItem(1).setVisible(true);
}
else{
isvisible = true;
m.getItem(0).setVisible(false);
m.getItem(1).setVisible(false);
}
return super.onPrepareOptionsMenu(m);
}
I need the remaining two items to be shown when i click on the menu item rather than on the menu button.
Can anyone suggest me please
override the below method:
The above method is called every time before the menu is shown.
EDIT:
By default
set bool to falseandon false show the menu and set the bool to trueand on next call check this bool and if it is true, set it false and make the menu invisible.use this line to make the menu visible or invisible:menu.getItem(index).getSubMenu().getItem(index).setVisible(true);Store the bool in
sharedpreference.