1

我目前有一个 AlertDialog,用户可以从三个选项中进行选择(在名为 itemsOutput1 的数组中定义)。尽管我希望能够通过将默认选择设置为先前存储的共享首选项来预测用户将根据先前的选择给出的答案,但这很好用。

假设我知道我想将默认选择设置为 itemsOutput1 中的第二项,如何将其应用于 .setSingleChoiceItems 以便在出现对话框时已经选择第二项?

case 1:
return new AlertDialog.Builder(this)
.setIcon(bmd)
.setTitle("What do you want the output to be?")
.setPositiveButton("OK", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) 
    {
callShapeActivity();
}
})
.setSingleChoiceItems(itemsOutput1, 0, new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
//---get the SharedPreferences object---
prefs = getSharedPreferences(prefName, MODE_PRIVATE);
SharedPreferences.Editor editor = prefs.edit();

//---set the user inputs to prefo's---
editor.putString(OUTPUT_KEY, itemsOutput1[which]);
editor.commit(); 
}
    }
)
.create();
4

1 回答 1

0

Look at this previous answer link.

If I understand your question well, this will be helpful to you.

于 2012-10-09T11:17:54.590 回答