Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android -- Problems with Checkable menu items

I have read the instructions at the android developers page's in order to get the Checkable menu items:

http://developer.android.com/guide/topics/ui/menus.html

this is my xmlmenu:

<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android">
    <group android:checkableBehavior="all">
        <item android:id="@+id/regu"
              android:title="@string/Regulatory" />
        <item android:id="@+id/warn"
              android:title="@string/Warning" />
        <item android:id="@+id/temp"
              android:title="@string/Temporary" />
        <item android:id="@+id/bicy"
              android:title="@string/Bicycle" />
    </group>
</menu>

And here is my code:

 @Override
    public boolean onOptionsItemSelected(MenuItem item) {
      switch (item.getItemId()) {
      case R.id.regu:
          if (item.isChecked())
          {
              item.setChecked(false);
              currAvailableOptions++;
          }
          else if(0 != currAvailableOptions)
          {
                  item.setChecked(true);
                  currAvailableOptions--;
          }
          return true;
      case R.id.warn:
          if (item.isChecked())
          {
              item.setChecked(false);
              currAvailableOptions++;
          }
          else if(0 != currAvailableOptions)
          {
                  item.setChecked(true);
                  currAvailableOptions--;
          }
        return true;
      case R.id.temp:
          if (item.isChecked())
          {
              item.setChecked(false);
              currAvailableOptions++;
          }
          else if(0 != currAvailableOptions)
          {
                  item.setChecked(true);
                  currAvailableOptions--;
          }
          return true;
      default:
        return super.onOptionsItemSelected(item);
      }
    }

public boolean onCreateOptionsMenu(Menu menu) {
        MenuInflater inflater = getMenuInflater();
        inflater.inflate(R.menu.app_menu, menu);
        return true;
    }

The problem is when I clicked one item, the menu item disappeared. It wouldn't have to stay visible in order to check other menu items?

Any idea?

Greetings

like image 556
andrestoga Avatar asked Apr 30 '11 19:04

andrestoga


1 Answers

Checkable items appear only in submenus or context menus.

And with submenu they (Google) means:

Submenu A floating list of menu items that appears when the user touches a menu item that contains a nested menu.

Since your menu items are not submenu items, it will not work

like image 94
Entreco Avatar answered Oct 12 '22 09:10

Entreco