how to hide an item in the menu

2

I created a menu with buttons to save, to go back and to add, and I would like that when I clicked on add it was hidden or that it is disabled. I tried to use MenuItem item = menu.findItem(R.id.my_item); that I saw in this topic but it is marked with a red scratch below the line and the unreachable statement message is displayed when you mouse over. any hint how can I hide the item in the menu?

    
asked by anonymous 02.01.2018 / 20:02

1 answer

3

Just instantiate the menu:

Menu menu = navView.getMenu();

and set the attribute visible

menu.findItem(R.id.my_item).setVisible(false);

The error unreachable statement is due to some logic error in your code, which means that the declaration is inaccessible .

Maybe you're giving return in the above line, for example.

    
02.01.2018 / 20:22