1

I need to have a single radiobutton that I can check and uncheck.

But from my readings on stack overflow, the radio button will stay checked once it is checked as on option needs to be selected?

Here is my code so far:

            RadioButton rButton = new RadioButton(getActivity());
            rButton.setText(listItems.get(i));
            rButton.setId(i);
            rButton.setChecked(false);
            rButton.setClickable(true);
            // rButton.setOnClickListener(new View.OnClickListener() {
            // @Override
            // public void onClick(View v) {
            // RadioButton rButton = (RadioButton)
            // layout.findViewById(position);
            // rButton.setChecked(!rButton.isChecked());
            // }
            // });              
            layout.addView(rButton);

it does work even with the commented out onclick listener.

How can i get the radio button to uncheck?

Zapnologica
  • 22,170
  • 44
  • 158
  • 253
  • Radio buttons require exactly one in the set to be checked. – Moob Oct 07 '13 at 15:36
  • radiobuttons are in a radiobuttongroup (otherwise it doesn't really make any sense), and radiobuttongroup uses the `clear` method to remove a selection. – njzk2 Oct 07 '13 at 15:39
  • 1
    `(RadioButton) layout.findViewById(position);` I don't know what `position` is, but I doubt it is the id of the radioButton – njzk2 Oct 07 '13 at 15:40

1 Answers1

4

I think you need a CheckBox Instead.

stinepike
  • 54,068
  • 14
  • 92
  • 112