質問

Can someone tell me where am I doing a mistake? Why can both RadioButtos be selected even though I put them into RadioGroup?

Here's the Code:

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)
役に立ちましたか?

解決

You need to first add the Radiobutton to the RadioGroup and only then call

rb_no.setChecked(true);
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top