I need to check the box when I click on the menu item, but for some reason it does not work for me. Can someone help with this?
<group
android:id="@+id/checkable_group"
android:checkableBehavior="all">
<item
android:id="@+id/silence_remove"
android:title="@string/silence_remove"
/>
<item
android:id="@+id/noise_suppression"
android:title="@string/noise_suppression"
/>
</group>
I open the menu with Popup
private void showPopup(View v){
popup = new PopupMenu(getActivity(), v);
MenuInflater inflater = popup.getMenuInflater();
inflater.inflate(R.menu.noise_suppression_menu, popup.getMenu());
Log.v(LOG_TAG, ". showPopup");
popup.setOnMenuItemClickListener(new PopupMenu.OnMenuItemClickListener() {
@Override
public boolean onMenuItemClick(MenuItem item) {
switch (item.getItemId()){
case R.id.silence_remove:
if(item.isChecked()){
item.setChecked(false);
Log.v(LOG_TAG, ". false");}
else{
item.setChecked(true);
popup.getMenu().getItem(0).setChecked(true);
Log.v(LOG_TAG, ". true");}
return true;
case R.id.noise_suppression:
if(item.isChecked())
item.setChecked(false);
else
item.setChecked(true);
popup.getMenu().getItem(1).setChecked(true);
return true;
default:
return false;
}
}
});
popup.show();
}
When I click on a menu item, it says "true", but does not note it in any way. And it is necessary that he remember what I have allocated.
Aucun commentaire:
Enregistrer un commentaire