问题描述
大家好,在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();
}
这是工作和伟大的。
which is working and great.
但要注意行
dialog.setSingleChoiceItems(phoneNums, 0,
new DialogInterface.OnClickListener() {
phoneNums是假设每一个对话框弹出时间来改变。我重写的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.
这是我在prepareDialog方法
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.
推荐答案
您需要使用getListView方法从AlertDialog类。然后使用setItemChecked方法对返回的对象。例如:
You need to use getListView method from AlertDialog class. Then use setItemChecked method on returned object. Example:
alertDialog.getListView()setItemChecked(1,真)。
alertDialog.getListView().setItemChecked(1, true);
这篇关于如何在prepareDialog设置setSingleChoiceItems的内容?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!