1

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

2 Answers 2

2

use onPrepareOptionsMenu method and clear all menu first using

menu.clear(); 

then add menu.

Sign up to request clarification or add additional context in comments.

Comments

1

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

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.