Code example for Spinner

Methods: getItemAtPosition, getSelectedItemPosition

0
        // Apply the adapter to the spinner 
        sp.setAdapter(adapter);
    } 
 
    public void readPref(View v) {
    	String key = sp.getItemAtPosition(sp.getSelectedItemPosition()).toString();
    	SharedPreferences sharedPref = PreferenceManager.getDefaultSharedPreferences(this);
    	String pref = null;
    	if (key.startsWith("pref_text")) pref = sharedPref.getString(key, "");
    	else if (key.startsWith("pref_chkbx")) pref = Boolean.toString(sharedPref.getBoolean(key, false));
    	else if (key.startsWith("pref_list")) pref = sharedPref.getString(key, "");
 
    	Toast.makeText(this, "Key: "+key+" | Value: "+pref, Toast.LENGTH_LONG).show();
    } 
}