-1

有人可以告诉我我在哪里做错了吗?为什么即使我将它们放入 RadioGroup 中,也可以选择两个 RadioButton?

这是代码:

final Dialog dialog = new Dialog(context);
LinearLayout ll = new LinearLayout(context);
ll.setOrientation(LinearLayout.VERTICAL);
dialog.setTitle("Title");

RadioButton rb_yes = new RadioButton(context);
rb_yes.setText("yes");

RadioButton rb_no = new RadioButton(context);
rb_no.setText("no");
rb_no.setChecked(true);

RadioGroup radioGroup = new RadioGroup(context);
radioGroup.setOrientation(RadioGroup.VERTICAL);
radioGroup.addView(rb_yes);
radioGroup.addView(rb_no);

ll.addView(radioGroup);

// "context" I've already created before (Context context = this)
4

1 回答 1

1

您需要先添加Radiobutton到,RadioGroup然后才调用

rb_no.setChecked(true);
于 2013-12-22T12:43:03.863 回答