如何设置内部AlertDialog单一选择项目? [英] How to set Single Choice Items inside AlertDialog?

查看:159
本文介绍了如何设置内部AlertDialog单一选择项目?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我还没有能够建立一个单一的选择列表或多重选择列表内的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.

这篇关于如何设置内部AlertDialog单一选择项目?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆