Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

android:checkableBehavior set programmatically

I am creating a Menu in Android XML and adding via code a submenu. Now I want that only one menu-point to be checked. In XML it would be android:checkableBehavior="single". But how can I realize this in code?

like image 820
Erdnuss Avatar asked Dec 17 '25 14:12

Erdnuss


1 Answers

Use

MySubMenu.setGroupCheckable(int groupId, boolean checkable, boolean exclusive);

exclusive = true //to pick only one menu-point as android:checkableBehavior="single"

For example:

MySubMenu.setGroupCheckable(0, true, true);

*Add this function after all your submenu items were defined

like image 91
dianakarenms Avatar answered Dec 19 '25 03:12

dianakarenms



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!