How to programmatically make CheckBox flag true in Navigation Drawer? it is programmatically that is, when you start it will be a checkbox, you need to implement not via XML
- On the screenshot, this is not NavigationDrawer, but popup menu of the action bar. NavigationDrawer is something that goes to the side and switches the screens in the application. - pavlofff
|
1 answer
I give my example. This is the markup of this element in xml.
<item android:id="@+id/menuCheck" android:checkable="true" android:checked="false" android:title="check" app:showAsAction="never" /> The menu is not a View, which is why you cannot findViewById to find an item in the menu and check the box. To check the box programmatically, you need to override the onCreateOptionsMenu method in the Activity:
@Override public boolean onCreateOptionsMenu(Menu menu) { MenuInflater menuInflater = getMenuInflater(); menuInflater.inflate(R.menu.menu_main, menu); menu.findItem(R.id.menuCheck).setChecked(true); return true; } |
