I got a radio button in a radio group. It is dynamically created, so I haven't got the reference to the radio group the button is in. I would like to make it able for the app user to uncheck a radiobutton by again clicking on it. I tried a view things but couldn't succeed.
How do I do this?
I tried the following code:
rButton.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (((RadioButton) v).isChecked()) {
((RadioButton) v).setSelected(false);
}
}
});
Problem is, that this if-clause is always true also if you press the radiobutton for the first time. AND more important the setSelected(false) doesn't work.
Thank you for any advice.
Edit: I mad this foolish mistake of using setSelected instead of setChecked. So with setChecked I can uncheck the radioButton. But so it is never checked, not even the first time.