Question

Hi in my application I need to add Some menu items. The problem is, one menu item should only display when the focus is on one of the listview items.

Simply one of the menu items should only display if the focus is on at one the of the listview items. When the focus is at anywhere else then should display only the other menu items except that. Other menu items will display always.

I can track the focus. I tried to run following code only when focus is on listview.

menu.add(0, Menu.FIRST, 0, "Add to favourite List"); [Problem: if I press menu button more than one time while focus there it creates new menu item each time when I press the menu button.]

I am inflating from xml menu and create others.

Can anyone guide me how to do this... Thanks

Was it helpful?

Solution

use onPrepareOptionsMenu method and clear all menu first using

menu.clear(); 

then add menu.

OTHER TIPS

You could have a variable to keep track of whether that menu item was added or not.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top