Use checkbox state to determine attribute of another XML element

47 views Asked by At

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 XML below 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()}" />
0

There are 0 answers