Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How get selected option from ListPreference?

I have ListPreference and it contains for example 5 options and I want to save one of this value to SharedPreferences when user selects it. How can I do it?

btw. I know how to save value to SharedPreferences, but I don't know how to get that value when user selects one of them.

like image 934
Adam Avatar asked Mar 20 '12 17:03

Adam


1 Answers

OnPreferenceChangeListener listener = new OnPreferenceChangeListener() {    
    @Override
    public boolean onPreferenceChange(Preference preference, Object newValue) {
        // newValue is the value you choose
        return true;
    }
};

listPreference.setOnPreferenceChangeListener(listener);
like image 145
Ethan Liou Avatar answered Sep 17 '22 07:09

Ethan Liou