I cannot retrieve the selected value of the spinner. Can somebody help me? Thanks.
This is how I retrieve the data. It’s inside the onCreate() method.
mPrefs = getSharedPreferences(PREFS_NAME, MODE_PRIVATE);
SpinnerLang.setSelection(mPrefs.getInt(PREF_SPINNER, 0));
Then I save the Spinner’s value in a button, so when the user selects from the Spinner and clicks the button the selected value will be saved.
//Listening to button event
btnDone.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Editor e = mPrefs.edit();
int Spinnervalue = SpinnerLang.getSelectedItemPosition();
e.putInt("PREF_SPINNER", Spinnervalue);
e.commit();
}
Use a
spinner.setOnItemSelectedListener()to store the selected item position in preference