如何设置内部AlertDialog单一选择项目?如何设置、项目、AlertDialog

2023-09-05 05:30:34 作者:烟花再美丶只是瞬间

我还没有能够建立一个单一的选择列表或多重选择列表内的AlertDialog。

I haven't been able to set a Single Choice list, or a Multiple Choice List inside an AlertDialog.

我想下面的例子,但我只得到一个对话框,标题,确定和取消按钮,也没有清单,并且没有信息(这是我定!)。

I tried following the examples but I only get a Dialog with a Title, the Ok and Cancel buttons, and no list, and NO message (which I set!).

下面是code:

    protected Dialog onCreateDialog(int id) {
    switch (id) {
    case DIALOG_DELETE_CITY:
        CharSequence[] array = {"Red", "Blue", "Yellow"}; 
        return new AlertDialog.Builder(ShowPypData.this)
            .setTitle(R.string.city_actions_delete_label)
            .setMessage(R.string.city_actions_delete_select_label)
            .setSingleChoiceItems(array, -1, new DialogInterface.OnClickListener() {

                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        // TODO Auto-generated method stub

                    }
                })
            .setPositiveButton(android.R.string.ok, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    // TODO Auto-generated method stub

                }

            })
            .setNegativeButton(android.R.string.cancel, new DialogInterface.OnClickListener() {

                @Override
                public void onClick(DialogInterface dialog, int which) {
                    dialog.dismiss();

                }
            }).create();
    default:
        return null;
    }

}

奇怪的是,如果我评论的setSingleChoiceItems部分,我可以看到该消息的对话框。

The weird thing is that if I comment the setSingleChoiceItems part, I can see the message on the dialog.

推荐答案

看来,按钮,消息和多选择的项目是相互排斥的。试评出来setMessage,setPositiveButton和setNegativeButton。没有检查它自己。

Seems that Buttons, Message and Multiple choice items are mutually exclusive. Try to comment out setMessage, setPositiveButton and setNegativeButton. Didn't check it myself.

 
精彩推荐
图片推荐