I have a string that i get from asynctask, i would like to set that string as title of menu item in actionbar.
@Override
public boolean onCreateOptionsMenu(Menu menu) {
MenuInflater inflater = getMenuInflater();
inflater.inflate(R.menu.main, menu);
this.menu = menu;
if (menu!= null) {
menu.findItem(R.id.azzera).setVisible(false);
}
MenuItem giornataItem = menu.findItem(R.id.giornata);
giornataItem.setTitle(giornataTitle);
return super.onCreateOptionsMenu(menu);
}
/* Called whenever we call invalidateOptionsMenu() */
@Override
public boolean onPrepareOptionsMenu(Menu menu) {
// If the nav drawer is open, hide action items related to the content view
MenuItem giornataItem = menu.findItem(R.id.giornata);
giornataItem.setTitle(giornataTitle);
return super.onPrepareOptionsMenu(menu);
}
OnPrepareOptionsMenu works fine, when i change fragment or drawernav is open the title is still correct, but onCreateOptionsMenu does not set the title on application start because in that moment the string is null, because it's called before asynctask. How can i set that string as title?