I want to implement an android spinner with key value .
en:english jp:japanese
And when user select and item I want to save key to database . And also on next load I want spinner to select a particulate spinner position.
Can any one please tell me what is the best way to implement this.
I have tried following but doesn't met my requirement https://gist.github.com/granoeste/2786663 Set Key and Value in spinner
Write now I am using LinkedHashMapAdapter. But issue is that here I need to store position in DB or local shared preference . I don't think this a better solution
Current Implementation
LinkedHashMap localeList = new LinkedHashMap<>();
for (Map.Entry<String, String> val : map.entrySet()) {
int resourceId = getResources().getIdentifier(val.getValue(), "string", getPackageName());
localeList.put(val.getKey(), getResources().getString(resourceId));
}
LinkedHashMapAdapter<String, String> arrayAdapter = new LinkedHashMapAdapter<>(this, R.layout.spinner_layout, localeList);
arrayAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);
mLocale.setAdapter(arrayAdapter);
String localPosSelected = PreferencesHelper.getSharedPreferenceString(this, Constants.PREF_LOCALE_POS_KEY);
if(localPosSelected!=null){
mLocale.setSelection(Integer.parseInt(localPosSelected));
}
Also is there an option to selected item of Spinner by value