Neelay Srivastava Neelay Srivastava - 9 months ago 50
Android Question

setting radio button for different task

I am trying to show radio group in a dialog and when the radio button is clicked it will set some data in shared preference. I am able to make toast when any button is clicked but I want to do something when different button is clicked .I tried setting Onclick in the radio button but it is not working .I am trying to learn from here
this is my dialog class

public Activity c;
public Dialog d;
public Button yes, no;
public RadioGroup radioGroup;
public RadioButton radioButton;

public CustomDialogClass(Activity a) {
// TODO Auto-generated constructor stub
this.c = a;

protected void onCreate(Bundle savedInstanceState) {
yes = (Button) findViewById(;
no = (Button) findViewById(;

private void Radioactive() {
radioGroup = (RadioGroup) findViewById(;
int selectedId = radioGroup.getCheckedRadioButtonId();
radioButton = (RadioButton) findViewById(selectedId);


I just want to know how to do some thing when specific radio button is checked.


You can achieve the radio button click as follows.

 `radioGroup.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() { public void onCheckedChanged(RadioGroup group, int checkedId) { // checkedId is the RadioButton selected RadioButton rb=(RadioButton)findViewById(checkedId); textViewChoice.setText("You Selected "+rb.getText()); //Toast.makeText(getApplicationContext(), rb.getText(), Toast.LENGTH_SHORT).show(); } });`

hope it will help .