Change the second argument (checkedItem) in setSingleChoiceItems from -1 to any switch position you want to check, here I changed it to "1", so the first radio button will be checked.
alertDialogBuilder.setSingleChoiceItems(items, 1, new DialogInterface.OnClickListener() { public void onClick(DialogInterface dialog, int item) { Toast.makeText(SettingAppDisplay.this, "You selected item No." + item + ": " + items[item], Toast.LENGTH_SHORT).show(); if (items[item].equals("5")) { //do what you want } else if (items[item].equals("10")) { //do what you want } else if (items[item].equals("15")) { //do what you want } else if (items[item].equals("20")) { //do what you want } dialog.dismiss(); } });
See docs
setSingleChoiceItems (Cursor cursor, int checkedItem, String labelColumn, DialogInterface.OnClickListener listener)
Options
cursor cursor to extract items from.
checkedItem indicates which item is checked. If -1 items are not marked.
labelColumn The name of the column in the cursor containing the row displayed in the label.
The listener is notified when an item in the list is clicked. The dialog will not be rejected when an item is clicked. It will be rejected only when the button is clicked, if no buttons are provided to the user to close the dialog box.
source share