質問

i created a menu that needs to change depending on user input and the menu does change but only once the user opens the menu twice. my guess is that the original menu is built by public boolean oncreateOptionsMenu(Menu menu) but it is not actually updated until further menu button presses are done using public boolean onPrepareOptionsMenu(Menu menu) so i was wondering if their was a way to tell the menu to update itself the first time that it opens. i have tried the following and have seen no results:

public boolean onCreateOptionsMenu(Menu menu){
onPrepareOptionsMenu(menu);
MenuInflator inflater = getMenuInflater();
inflater.inflate(R.menu.menu_list, menu);
return true;
}

is their any way i can make the changes in my onPrepareOptionsMenu function happen the first time the menu is opened? if i put the action of the onPrepareOptionsMenu the menu is not modified, for some reason it sees values that are old and there fore does not make any changes

役に立ちましたか?

解決

i fixed my problem by using the function closeOptionsMenu() before the action that the user performs. i thought that the menu was first built when the user pressed the menu button but it seems that the menu is first built on startup and the menu button will call that first and then call onprepareoptionsmenu(). close options menu most likely forces onprepareoptionsmenu on the first menu button try but i am not entirely sure.

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top