I read the instructions on the Android developers page to get the Check 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 that when I clicked one item, the menu item disappeared. No need to stay visible to check other menu items?
Any idea?
Greetings
source share