如何使用侧面的单选按钮创建警告对话框?

时间:2009-10-30 05:07:32

标签: android

如何在侧面创建AlertDialog RadioButton? 我可以使用Dialog创建一个包含3个选择字符串的AlertDialog.Builder,但是如何在旁边创建一个RadioButton的字符串(即只允许1个选择)?

谢谢。

3 个答案:

答案 0 :(得分:1)

我不确定你是否正在使用Material Design,或者你是否仍然需要在6年后回答这个问题,但是对于任何可能正在寻找这个问题的人来说,这就是答案

    new MaterialDialog.Builder(this)
                        .title(R.string.which_phone_number)
                        .items(contactPhonesArr)
                        .itemsCallbackSingleChoice(0, new MaterialDialog.ListCallbackSingleChoice() {
                            @Override
                            public boolean onSelection(MaterialDialog dialog, View view, int which, CharSequence text) {
                                    //Do really cool things here
                                    dialog.dismiss();
                                }
                                return true;
                            }
                        })
                        .positiveText("Choose")
                        .show();

答案 1 :(得分:1)

你可以试试这个:

AlertDialog levelDialog;
// Strings to Show In Dialog with Radio Buttons
final CharSequence[] items = {" Easy "," Medium "," Hard "," Very Hard "};
// Creating and Building the Dialog 
AlertDialog.Builder builder = new AlertDialog.Builder(this);
builder.setTitle("Select The Difficulty Level");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
    public void onClick(DialogInterface dialog, int item) {
        // Your code
        levelDialog.dismiss();    
    }
});
levelDialog = builder.create();
levelDialog.show();

答案 2 :(得分:0)

或许在setView()中使用AlertDialog.Builder?很难说“侧面有单选按钮的那个”是什么意思。

相关问题