本文介绍了如何在onPrepareDialog中设置setSingleChoiceItems的内容?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在onCreateDialog中的人,我有这样的:

Guys, in onCreateDialog i have this:

case DIALOG_REVIEW: {
    if (bundle.containsKey("POSITION")) {
    final int position = bundle.getInt("POSITION");
    ArrayList<String> alterNumbers = numbers.get(position);
    final String[] phoneNums = new String[alterNumbers.size()];
    for (int i = 0; i < alterNumbers.size(); i++) {
        phoneNums[i] = alterNumbers.get(i);
    }
    AlertDialog.Builder dialog = new AlertDialog.Builder(this);
    dialog.setTitle(names.get(position) + "'s number(s)");
    dialog.setSingleChoiceItems(phoneNums, 0,
        new DialogInterface.OnClickListener() {

            @Override
            public void onClick(DialogInterface dialog,
                int which) {
            // get selected item and close the dialog
            String selectedNumber = phoneNums[which];
            updateUserSelectedNumber(position , selectedNumber);
            }
        });
    return dialog.create();
    }

这是非常有用的。

但请注意线

dialog.setSingleChoiceItems(phoneNums, 0,
        new DialogInterface.OnClickListener() {

phoneNums假设每次弹出对话框时都会更改
I我已经在PrepareDialog方法上覆盖了,但我不知道如何为它分配新的值
,也没有setSingleChoiceItems。

phoneNums are suppose to be changing each time the dialog pops up.I've overriden onPrepareDialog method but I don't know how to assign new values to it.and also there is no setSingleChoiceItems there.

这里是我的onPrepareDialog方法

here is my onPrepareDialog method

case DIALOG_REVIEW: {
    final int position = bundle.getInt("POSITION");
    ArrayList<String> alterNumbers = numbers.get(position);
    final String[] phoneNums = new String[alterNumbers.size()];
    for (int i = 0; i < alterNumbers.size(); i++) {
    phoneNums[i] = alterNumbers.get(i);
    }
    AlertDialog alertDialog = (AlertDialog) dialog;
    alertDialog.setTitle(names.get(position) + "'s number(s)");
    ???
    break;
}

有什么解决方案?
感谢提前的家伙。

What is the solution?thanks in advance guys.

推荐答案

您需要使用方法。然后在返回的对象上使用方法。示例:

You need to use getListView method from AlertDialog class. Then use setItemChecked method on returned object. Example:


alertDialog.getListView()。setItemChecked(1,true);

这篇关于如何在onPrepareDialog中设置setSingleChoiceItems的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

07-04 00:36