Я создал 1 радиогруппу, которая содержит 2 линейных макета. Эти 2 линейных макета содержат по 1 радиокнопке. Линейный макет был создан только для применения стиля как для радиогруппы, так и для текстового представления. когда мы проверили переключатель, эта кнопка проверила. Он работает нормально, но я хочу, чтобы переключить переключатель, когда я нажимаю линейный макет также. Есть ли решение, чтобы решить эту проблему. `
<RadioGroup
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:layout_marginTop="15dp"
>
<LinearLayout
android:id="@+id/layout1"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
style="@style/RadioButton">
<RadioButton
android:id="@+id/entireplace"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@null"
android:textColor="@android:color/tab_indicator_text"
android:drawableRight="@drawable/custom_checkbox"
android:text="@string/entireplace"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/entire_txt"/>
<View
android:layout_width="match_parent"
android:layout_height="0.3dp"/>
</LinearLayout>
<LinearLayout
android:id="@+id/layout2"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
style="@style/RadioButton">
<RadioButton
android:id="@+id/privatepalce
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:button="@null"
android:drawablePadding="30dp"
android:drawableRight="@drawable/custom_checkbox"
android:text="@string/privateroom"
/>
<TextView
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:text="@string/pvt_txt"/>
<View
android:layout_width="match_parent"
android:layout_height="0.3dp""/>
</LinearLayout>
</RadioGroup>
`
val onRadioButtonCheckedListener =
CompoundButton.OnCheckedChangeListener { buttonView, isChecked ->
if (!isChecked) return@OnCheckedChangeListener
if (previousCheckedCompoundButton != null) {
previousCheckedCompoundButton!!.isChecked = false
previousCheckedCompoundButton = buttonView
} else {
previousCheckedCompoundButton = buttonView
}
}
binding.entireplace.setOnCheckedChangeListener(onRadioButtonCheckedListener)
binding.private.setOnCheckedChangeListener(onRadioButtonCheckedListener)