我已阅读 android 开发者页面上的说明以获取 Checkable 菜单项:
http://developer.android.com/guide/topics/ui/menus.html
这是我的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>
这是我的代码:
@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;
}
问题是当我单击一项时,菜单项消失了。为了检查其他菜单项,它不必保持可见?
任何想法?
问候