0

我有一个 AlertDialogBox,我在上面放了单选按钮,但是我有一个问题,每当我点击它们时,它们都被选中了。将取消选择另一个.. 我该怎么做?这是我的代码..

 AlertDialog.Builder alert = new AlertDialog.Builder(this);



        alert.setTitle("Standard Deviation");
        alert.setIcon(R.drawable.droid);
        RadioButton one = new RadioButton(this);
        one.setText("one set");
        RadioButton two = new RadioButton(this);
        two.setText("two sets");


        LinearLayout ll=new LinearLayout(Treatment.this);
        ll.setOrientation(LinearLayout.VERTICAL);



        ll.addView(one);
        ll.addView(two);
        alert.setView(ll);


        AlertDialog alertDialog = alert.create();
        alertDialog.show();
4

2 回答 2

0

把它们放在RadioGroup这样的东西里:

AlertDialog.Builder alert = new AlertDialog.Builder(this);

alert.setTitle("Standard Deviation");
alert.setIcon(R.drawable.droid);

RadioButton one = new RadioButton(this);
one.setText("one set");
RadioButton two = new RadioButton(this);
two.setText("two sets");


RadioGroup rg=new RadioGroup(Treatment.this);
rg.setOrientation(RadioGroup.VERTICAL);


rg.addView(one);
rg.addView(two);
alert.setView(rg);


AlertDialog alertDialog = alert.create();
alertDialog.show();
于 2013-11-08T02:16:24.757 回答
0

我建议您在继续之前阅读有关对话框的文档。自定义对话框和多项选择对话框的示例在您的情况下将非常有用。尝试在 xml 中添加一个带有两个单选按钮的单选组,作为警报对话框的自定义布局。

于 2013-11-08T02:19:09.993 回答