How do you save the state of a dialog in android? I have the following dialog with radio buttons but can’t figure out how to save the state of the dialog. Thanks for any help
final CharSequence[] items = {"Item 1", "Item 2", "Item 3"};
AlertDialog.Builder builder = new AlertDialog.Builder(Tweaks.this);
builder.setTitle("Pick an item");
builder.setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int item) {
Toast.makeText(getApplicationContext(), items[item], Toast.LENGTH_SHORT).show();
}
}).show();
You should store the position of the selected item when the user clicks. Then you look for a previously stored index when you display the list. If there is no previously stored value you return -1.
I have an app Preferences helper class …
Then, in my code I create a field variable …
And instantiate an instance of it inside the Activity onCreate() …
Then replace your “-1” with …
And in your onClick() make sure you …