Prevent closing the menu immediately after onItemClicked is fired

I searched for a while, but could not find a solution. I have something like a Google button as a MenuItem, and I want to update it immediately when a user clicks on a menu item.

As for Android docs: http://developer.android.com/reference/android/view/Menu.html there is a flag called FLAG_PERFORM_NO_CLOSE.. I used it

menu.performIdentifierAction(R.id.myItem, Menu.FLAG_PERFORM_NO_CLOSE);

but you can imagine nothing is happening. The menu closes as quickly as before, without updating.

Android doesn't seem to update Menu-View until it closes. This looks very ugly and the user does not receive feedback if the item is selected before the menu opens.

Can someone help with how I earned?

The best solution for me would be if the menu item is updated and the menu closes, after which we say 200 ms not immediately.

Update

public boolean onMenuItemSelected(int featureId, MenuItem item) {
    // TODO Auto-generated method stub
return super.onMenuItemSelected(featureId, item);

This is the ne method that runs when an item is selected. It looks like the Menu has its own Scene handler. I could not find anything that would delay the closing of the menu or even its update. Hope this is clear now.

+4
source share
1 answer

Look at this:

  new Handler().postDelayed(new Runnable() {
  @Override
  public void run() {
  //write code you want to delay by 200 ms
  }
  }, 200);

You can visit Handler on the Android developer’s website.

0
source

All Articles