-1

I want to store position of Gujarati, Hindi and English and store into chechSum. so once it's selected, it remain selected when I open dialog again. ----------
final String[] languageList = {"ગુજરાતી", "हिन्दी", "English"}; int checkItem = 0; AlertDialog.Builder builder = new AlertDialog.Builder(BaseActivity.this); builder.setTitle("Choose Language..."); builder.setSingleChoiceItems(languageList, checkItem, new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int i) { if (languageList[i].equals("ગુજરાતી")) { //Gujarati setLanguage("gu"); recreate(); } else if (languageList[i].equals("हिन्दी")) { //Hindi setLanguage("hi"); recreate(); } else if (languageList[i].equals("English")) { //English setLanguage("en"); recreate(); } dialog.dismiss(); ; } }); AlertDialog alertDialog = builder.create(); int selectedPosition = (alertDialog).getListView().getCheckedItemPosition(); toast(String.valueOf(selectedPosition)); alertDialog.show(); }

MIT PATEL
  • 31
  • 7

1 Answers1

0

You get the index of the clicked item as "int i" in the onClick method and can use it to select the correct item from the languageList by calling languageList.get(i);

Retrieving the selected position before showing the alertdialog does not work, the user has to interact with the dialog first.

slowcar
  • 314
  • 2
  • 13