0

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) {
    super(a);
    // TODO Auto-generated constructor stub
    this.c = a;
}

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    requestWindowFeature(Window.FEATURE_NO_TITLE);
    setContentView(R.layout.custom_dialog);
    yes = (Button) findViewById(R.id.btn_yes);
    no = (Button) findViewById(R.id.btn_no);
    yes.setOnClickListener(this);
    no.setOnClickListener(this);
    Radioactive();
}

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




}

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

Neelay Srivastava
  • 1,041
  • 3
  • 15
  • 46

1 Answers1

1

You can achieve the radio button click as follows. For more details android onCheckedChanged for radiogroup for different function

radioGroup
    .setOnCheckedChangeListener(new OnCheckedChangeListener() {

        @Override
        public void onCheckedChanged(RadioGroup group, int checkedId) {
 Log.d("chk", "id" + checkedId);

            if (checkedId == R.id.a) {
                //some code
            } else if (checkedId == R.id.b) {
                //some code
            }

        }

    });
Community
  • 1
  • 1
Rajendra
  • 484
  • 4
  • 19