I have a radio button group that has four radio buttons. I am trying to create a scenario were when a user clicks on a radio button the value of that radio button would be display to him. But my code is not working.
This is my radio button group calling the onclick listener
buttongroup.setOnClickListener(buttongroupListener);
The line above is placed in the onCreate View.
private OnClickListener buttongroupListener = new OnClickListener(){
@Override
public void onClick(View view) {
// TODO Auto-generated method stub
String selectedValue = "";
// Is the button now checked?
if(view.getId() == R.id.buttoncontainer){
boolean checked = ((RadioButton) view).isChecked();
int selectedRadioID = buttongroup.getCheckedRadioButtonId();
if(checked){
switch(selectedRadioID){
case R.id.radioButton1:
selectedValue = "A";
break;
case R.id.radioButton2:
selectedValue = "B";
break;
case R.id.radioButton3:
selectedValue = "C";
break;
case R.id.radioButton4:
selectedValue = "D";
break;
}
}
}
Toast.makeText(context, selectedValue,Toast.LENGTH_SHORT).show();
}
};