I have a radio group used to set data class properties. Here's how I've gone so far: I manually set the "bankDestination" view to invisible if proxy_bi_fast is checked. However the "bankDestination" view is still visible.
fun onRadioButtonClicked(view: View) {
if (view is RadioButton) {
val checked = view.isChecked
when (view.getId()){
R.id.proxy_BI_Fast ->
if (checked) {
binding.bankDestination.visibility = View.GONE
}
}
}
}
the related xml code:
<RadioGroup
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginTop="20dp"
android:orientation="horizontal"
app:layout_constraintEnd_toEndOf="parent"
app:layout_constraintHorizontal_bias="1.0"
app:layout_constraintStart_toStartOf="parent"
app:layout_constraintTop_toTopOf="parent">
<RadioButton
android:id="@ id/account_number"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="20dp"
android:layout_marginTop="20dp"
android:text="@string/account_number"
android:onClick="onRadioButtonClicked"/>
<RadioButton
android:id="@ id/proxy_BI_Fast"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_marginStart="90dp"
android:layout_marginTop="20dp"
android:text="@string/proxy_bi_fast" />
</RadioGroup>
CodePudding user response:
You haven't added onClick method in your proxy_BI_Fast radio button. Try adding that and then check.
CodePudding user response:
It wont' work android:onClick="onRadioButtonClicked"
in the RadioButton
instead of this you have to use setOnCheckedChangeListener
on the RadioGroup
as describe below.
binding.rbGroup.setOnCheckedChangeListener { group, checkedId ->
when (checkedId) {
R.id.proxy_BI_Fast -> {
binding.bankDestination.visibility = View.GONE
}
}
}