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();
}
Asked
Active
Viewed 25 times
-1

MIT PATEL
- 31
- 7
1 Answers
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
-
where I have to call languageList.get(i); and how can I pass that value in checkItem variable?? – MIT PATEL Apr 01 '20 at 14:14