0

I have a View (i.e. a TextInputLayout, Button, whatever) that is disabled but once the RadioButton is checked I want to enable that view. And, once the radioButton is unchecked, I want that view to be disabled. I want to do it using DataBinding, but it is not working... Help?

        <RadioGroup
            android:id="@+id/radio_group"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:orientation="horizontal">

            <RadioButton
                android:id="@+id/myself"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/myself"/>

            <RadioButton
                android:id="@+id/group"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:text="@string/group" />
        </RadioGroup>

        <com.google.android.material.textfield.TextInputLayout
            android:id="@+id/groups_layout"
            style="@style/MyAutoCompleteTextView.Layout.Dense"
            android:enabled="@{group.isChecked()}"/>
a_local_nobody
  • 7,947
  • 5
  • 29
  • 51
mantc_sdr
  • 451
  • 3
  • 17

1 Answers1

0

You need to set the listener of the radio button in your code and accordingly update a liveData, then here in the layout just use androd:enabled=@{VIEW_MODEL.LIVE_DATA}

NOTE : Make sure that you import the viewModel in the respective layout.

Kamal Nayan
  • 1,635
  • 1
  • 5
  • 19