I will explain with an example.
Suppose there is a layuot :
<RadioGroup android:id="@+id/radio_button_group" android:layout_width="match_parent" android:layout_height="wrap_content"> <RadioButton android:id="@+id/first_radio_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="First"/> <RadioButton android:id="@+id/second_radio_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Second"/> <RadioButton android:id="@+id/third_radio_button" android:layout_width="wrap_content" android:layout_height="wrap_content" android:text="Third"/> </RadioGroup>
Further:
private RadioGroup mRadioButtonGroup; ... mRadioButtonGroup = (RadioGroup) findViewById(R.id.radio_button_group); ... int radioButtonID = mRadioButtonGroup.getCheckedRadioButtonId(); View radioButton = mRadioButtonGroup.findViewById(radioButtonID); if (radioButton == null) { Toast.makeText(getApplicationContext(), "Пункт не выбран!", Toast.LENGTH_SHORT).show(); return; } switch (radioButton.getId()) { case R.id.first_radio_button: Toast.makeText(getApplicationContext(), "Выбран первый пункт", Toast.LENGTH_SHORT).show(); break; case R.id.second_radio_button: Toast.makeText(getApplicationContext(), "Выбран второй пункт", Toast.LENGTH_SHORT).show(); break; case R.id.third_radio_button: Toast.makeText(getApplicationContext(), "Выбран третий пункт", Toast.LENGTH_SHORT).show(); break; }
In your example, as far as I understand, the number of the selected item is index , respectively, you can process this value with the help of switch – case .