ich ein NavigationView mit Checkbox oder Schaltern erstellen will, ich will nur diese Funktion in meiner Navigation haben, um Elemente wechseln und es sollte einfach so funktionieren: Wenn ich einen Schalter wenden ein anderes wechselt in den Off-Zustand. Was ich tat, um einen Schalter haben, ist dies:Java android NavigationView mit Checkbox
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:orientation="horizontal" android:layout_width="match_parent"
android:layout_height="match_parent">
<android.support.v7.widget.SwitchCompat
android:layout_width="fill_parent"
android:layout_height="match_parent"
android:id="@+id/switchs"
/>
</LinearLayout>
<?xml version="1.0" encoding="utf-8"?>
<menu xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto">
<group android:checkableBehavior="single">
<item
android:id="@+id/nav_menu1"
android:icon="@mipmap/ic_launcher"
android:title="Menu 1" />
<item
android:id="@+id/nav_menu2"
android:icon="@mipmap/ic_launcher"
android:title="Menu 2" />
<item
android:id="@+id/nav_menu3"
app:actionLayout="@layout/action_view_switch"
android:icon="@mipmap/ic_launcher"
android:title="Menu 3" />
<item
android:id="@+id/nav_menu4"
app:actionLayout="@layout/action_view_switch"
android:icon="@mipmap/ic_launcher"
android:title="Menu 4" />
</group>
</menu>
Aber ich kann keinen Wert oder Status einen Schalter und einen Zuhörer haben ein Änderungsstand
Aber wie kann ich überprüfen, ob dieses Kontrollkästchen ausgewählt ist oder nicht? –
Ich habe versucht, aber versuchen Sie dies: ChechBox checkbox = (CheckBox) actionView.findViewById (R.id.checkbox); checkbox.setOnCheckChangeListner –