You can use the switch as follows:
XML Layout
<RadioGroup android:id="@+id/RG" android:layout_width="wrap_content" android:layout_height="wrap_content"> <RadioButton android:id="@+id/R1" android:layout_width="wrap_contnet" android:layout_height="wrap_content" android:text="R1" /> <RadioButton android:id="@+id/R2" android:layout_width="wrap_contnet" android:layout_height="wrap_content" android:text="R2" /> </RadioGroup>
And JAVA activity
switch (RG.getCheckedRadioButtonId()) { case R.id.R1: regAuxiliar = ultimoRegistro; case R.id.R2: regAuxiliar = objRegistro; default: regAuxiliar = null;
You also need to implement the onClick function with the button or setOnCheckedChangeListener function to get the required functionality.
source share