1

I am using the lib MaterialDrawer (https://github.com/mikepenz/MaterialDrawer). i can set SwitchDrawerItem true of false on drawerbuilder with the command below:

new SwitchDrawerItem().withName("Record audio").withIcon(FontAwesome.Icon.faw_microphone).withChecked(true).withIdentifier(111).withOnCheckedChangeListener(onCheckedChangeListener).withSelectable(false),

but now i have other method (using floating button) that will set this SwitchDrawerItem to true. i had tried

result.setSelection(111, true);

it only sets selection but not check the checkbox.

please help me . Many thanks.

Best regards, ben

mikepenz
  • 12,708
  • 14
  • 77
  • 117
Boy Wowor
  • 11
  • 3

1 Answers1

3

If you want to update an Item after the drawer was built there are multiple options. Either way you keep the reference to this item

SwitchDrawerItem myItem = new SwitchDrawerItem(). ...;

Or you get the Item from the Drawer again:

SwitchDrawerItem myItem = (SwitchDrawerItem) drawer.getDrawerItem(111);

After you have the reference to the item you can change it:

myItem.withChecked(false);

And then notify the MaterialDrawer about the update:

drawer.updateItem(myItem);

After this your Drawer will show the changed state.

You can also see all methods of the Drawer in it's JavaDoc

mikepenz
  • 12,708
  • 14
  • 77
  • 117