mercredi 30 novembre 2022

Use checkbox state to determine attribute of another XML element

I have a checkbox and a button in the same layout like in the sample code below. I want to make the button clickable only if checkbox is checked. I need to do it in XML without use of any listeners. The xmlbelow results in Cannot find identifier 'myCheckbox'

                <CheckBox
                    android:id="@+id/myCheckbox"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content" />

                <Button
                    android:id="@+id/myButton"
                    android:layout_width="match_parent"
                    android:layout_height="wrap_content"
                    android:clickable="@{myCheckbox.checked ? true : false}" />

I also tried to turn around the approach and call modifyButtonState, but it seems to never be called. There is no errors shown, but the method is not executed.

                  <CheckBox
                        android:id="@+id/myCheckbox"
                        android:layout_width="match_parent"
                        android:layout_height="wrap_content"                        
                        android:onCheckedChanged="@{()->handler.modifyButtonState()}" />



Aucun commentaire:

Enregistrer un commentaire