dd id to each
<RadioGroup
android:id="@+id/RB_options"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
<RadioButton
android:id="@+id/RB_op1"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="50"
android:onClick="onRadioButtonClicked"
android:text=""
android:visibility="visible" />
<RadioButton
android:id="@+id/RB_op2"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="50"
android:onClick="onRadioButtonClicked"
android:text=""
android:visibility="visible" />
<RadioButton
android:id="@+id/RB_op3"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="50"
android:onClick="onRadioButtonClicked"
android:text=""
android:visibility="visible" />
<RadioButton
android:id="@+id/RB_op4"
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:layout_weight="50"
android:onClick="onRadioButtonClicked"
android:text=""
android:visibility="visible" />
</RadioGroup>
in java
op1 = (RadioButton) findViewById(R.id.RB_op1);
op2 = (RadioButton) findViewById(R.id.RB_op2);
op3 = (RadioButton) findViewById(R.id.RB_op3);
op4 = (RadioButton) findViewById(R.id.RB_op4);
radioSelect = (RadioGroup) findViewById(R.id.RB_options);
this is the onclick methode
public void onRadioButtonClicked(View view) {
// Is the button now checked?
boolean checked = ((RadioButton) view).isChecked();
// Check which radio button was clicked
switch (view.getId()) {
case R.id.RB_op1:
if (checked)
Toast.makeText(LearnersTest_activity.this,
op1.getText().toString(), Toast.LENGTH_LONG).show();
break;
case R.id.RB_op2:
if (checked)
Toast.makeText(LearnersTest_activity.this,
op2.getText().toString(), Toast.LENGTH_LONG).show();
break;
case R.id.RB_op3:
if (checked)
Toast.makeText(LearnersTest_activity.this,
op3.getText().toString(), Toast.LENGTH_LONG).show();
break;
case R.id.RB_op4:
if (checked)
Toast.makeText(LearnersTest_activity.this,
op4.getText().toString(), Toast.LENGTH_LONG).show();
break;
}
}