Android invalidateOptionsMenu() for API < 11

Put your problem here if it does not fit any of the other categories.

Android invalidateOptionsMenu() for API < 11

Postby SnitramSD » Sun Dec 23, 2012 11:08 am

Hey everyone,

I used ActivityCompat.invalidateOptionsMenu(MainActivity.this); so that my menu item "Refresh" can automatically be enabled/disabled without the using have to touch the "Menu" option (imagine the user leaves the Menu open... I need the "Refresh" menu item to automatically disabled and enable itself).

The ActivityCompat.invalidateOptionsMenu(MainActivity.this) works fine in Android 11+. But what can I use for android API < 11 ? :S I've searched so much but I cannot find an answer. Can anyone please help me on this?

This works fine in Android API 11+, using the onPrepareOptionsMenu and ActivityCompat.invalidateOptionsMenu(MainActivity.this). The issue is trying to get it done in Android API < 11.

Here is my onPrepareOptionsMenu function:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. @Override
  2. public boolean onPrepareOptionsMenu(Menu menu) {
  3.  if(menuRefreshEnable){
  4.  menu.getItem(0).setEnabled(true);
  5.  }
  6.  if(!menuRefreshEnable){
  7.  menu.getItem(0).setEnabled(false);
  8.  }
  9.  return true;
  10. }
Parsed in 0.012 seconds, using GeSHi

I need the menu items to be updated without user interaction with the menu button. Imagine that the user leaves the menu open while my async task is running... With the line ActivityCompat.invalidateOptionsMenu(MainActivity.this) the menu itens are automatically updated in api 11+. If I remove it, it doesn't work. But I still need the automatic update of the menu itens in android api < 11.

When my async tasks finishes I execute the line ActivityCompat.invalidateOptionsMenu(MainActivity.this); in order to update the menu itens. But it only works in api 11+. How can I force the menu items to be updated in api < 11 without user interaction with the menu button (something similar to ActivityCompat.invalidateOptionsMenu(MainActivity.this); in api < 11)?

Thank you !
Once Poster
Once Poster
Posts: 1
Joined: Sun Dec 23, 2012 11:05 am


Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 13 guests