the menu will close and not reopen, only if i reclick on the menu button i see the new value
I don't know of anyway to keep the options menu open after an item has been selected, however you can reopen it automatically with a Handler and Runnable.
Create a couple new field variables:
private Handler handler = new Handler();
private Runnable reopenMenu = new Runnable() {
@Override
public void run() {
openOptionsMenu();
}
};
And inside onOptionsItemSelected()
use:
if(item.getItemId() == R.id.refresh)
{
refresh = true;
invalidateOptionsMenu(); // This is only necessary for changing an ActionBar
handler.postDelayed(reopenMenu, 100);
}
(Notice I removed the calls to close and open the menu.)
Lastly you should set refresh = false;
in onPrepareOptionsMenu()
since you only need to make the change once.