I currently have an AlertDialog where the user can choose from three options (defined in an array called itemsOutput1). This works fine although I want to be able to predict the answer the user will give based on previous selections, by setting the default selection to a previously stored shared preference.
Say I know that I want to set the default selected as the 2nd item in itemsOutput1, how do I apply this to the .setSingleChoiceItems so that the 2nd item is already selected when the dialog box appears?
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();