1

私は現在、ユーザーが 3 つのオプション (itemsOutput1 という配列で定義されている) から選択できる AlertDialog を持っています。デフォルトの選択を以前に保存された共有設定に設定することにより、以前の選択に基づいてユーザーが与える答えを予測できるようにしたいのですが、これはうまく機能します。

itemsOutput1 の 2 番目の項目として選択されたデフォルトを設定したいのですが、ダイアログ ボックスが表示されたときに 2 番目の項目が既に選択されているように、これを .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 に答える