1

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();
SubbaReddy PolamReddy
  • 2,083
  • 2
  • 17
  • 23
Kurt
  • 767
  • 8
  • 23

1 Answers1

0

Look at this previous answer link.

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

Community
  • 1
  • 1
Omarj
  • 1,151
  • 2
  • 16
  • 43
  • This helps me set the default value to the sharedPreferences, but I also want the defaultvalue to be highlighted on the AlertDialog so that the user knows if they do not select anything that this is the one that will be automatically saved for them – Kurt Oct 09 '12 at 11:22