Skip to content

Instantly share code, notes, and snippets.

@nein37
Created August 31, 2014 07:01
Show Gist options
  • Save nein37/3a7d423502404e52e21e to your computer and use it in GitHub Desktop.
Save nein37/3a7d423502404e52e21e to your computer and use it in GitHub Desktop.
ActionBarのメニューにCheckBoxを表示する ref: http://qiita.com/nein37/items/d0c01daf240f3f585092
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
xmlns:tools="http://schemas.android.com/tools"
tools:context=".MyActivity">
<group android:checkableBehavior="single">
<item
android:id="@+id/action_radio1"
android:title="ラジオ1"
app:showAsAction="never" />
<item
android:id="@+id/action_radio2"
android:title="ラジオ2"
app:showAsAction="never" />
</group>
</menu>
@Override
public boolean onCreateOptionsMenu(Menu menu) {
getMenuInflater().inflate(R.menu.menu, menu);
return true;
}
@Override
public boolean onOptionsItemSelected(MenuItem item) {
int id = item.getItemId();
switch (id){
case R.id.action_radio1:
item.setChecked(!item.isChecked());
Toast.makeText(this,"action_radio1",Toast.LENGTH_SHORT).show();
return true;
case R.id.action_radio2:
item.setChecked(!item.isChecked());
Toast.makeText(this,"action_radio2",Toast.LENGTH_SHORT).show();
return true;
}
return super.onOptionsItemSelected(item);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment