How can I add an Action Bar Item during run time?
I am using actionBarSherlock
, and I need to add some buttons when an event occurs (get some texts from a RSS, for example). I can't rely on a fixed xml.
How can I add an Action Bar Item during run time?
I am using actionBarSherlock
, and I need to add some buttons when an event occurs (get some texts from a RSS, for example). I can't rely on a fixed xml.
You can create the menu in code like this:
Inside check for a boolean.
You will need to call supportInvalidateOptionsMenu() to recreate the menu.
You can maintain a flag that determines if you need to display your button
then, override the method onCreateOptionsMenu(Menu menu) and check to see if hasRss is true or false. If true, add your button to do whatever. Then you can add your normal buttons you want to always show up regardless if you have the RSS or not
you will have to set your hasRss value = true whenever you retrieve your values and call
invalidateOptionsMenu();
to reload the action bar menu items