-4

I have made a menu.. it apper after clicking on button and when I click on the menu item.. the title of that Item shows in textView.. but I want give the user the ability to add new menu item.. so how can I creat new menu item from java class ?

I hope the question is clear enough .. and thanks anyway

  • it's not a question, it's a request for code. If you have made a minimal research, you'll have seen that those requests are downvoted and closed pretty quickly – njzk2 Aug 18 '15 at 20:25

1 Answers1

0

If I understand what you mean, you want to add an actionbar button programmatically during runtime.

If you did some search you would have find the following:

@Override
public boolean onCreateOptionsMenu(Menu menu)
{
    menu.add(0, 0, 0, "New Item 1").setIcon(R.drawable.ic_menu_new1)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);
    menu.add(0, 1, 0, "New Item 2").setIcon(R.drawable.ic_menu_new2)
            .setShowAsAction(MenuItem.SHOW_AS_ACTION_IF_ROOM);

    return true;
}
  • First, I'm using menu as a listView to show text I have add to each item title.. second I made popup window contain a textview and button, the textview let the user enter the text they want, then I use this text as a title for a new menu item I will add to the menu.. so only a want to know how to creat new item from java classes for a menu already exist in the app. And thanks for your answer :) – user5240774 Aug 18 '15 at 21:08