I have to dynamically change the onCreateOptionsMenu
items. I am fetching the items from a web service. But the problem is that the service is called in onCreate()
and in an AsyncTask
class so before the data from the service arrives onCreateOptionsMenu
gets called and returns NullPointerException
.
Here's how I am calling the function:
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// super.onCreateOptionsMenu(menu);
getMenuInflater().inflate(R.menu.action_bar_menu, menu);
item = menu.findItem(R.id.CurrentUser);
UserName = con.getResources().getString(R.string.WelcomeUser) + " "
+ UserName + "!";
item.setTitle(UserName);
if (IsCorporateAccount) {
menu.getItem(6).setVisible(true);
} else {
menu.getItem(6).setVisible(false);
}
objGetBalanceDetails.CreateMenu(menu);
// Menu menu1 = null;
// menu1.findItem(R.id.Home).setVisible(false);
return true;
}