开发者

get the selected preference value in android

开发者 https://www.devze.com 2023-02-15 09:31 出处:网络
Is there any way to get the newly selected value for a list preference. I have tried to get the values using onClick and onChange methods, but both of them returning the previous value. I understand t

Is there any way to get the newly selected value for a list preference. I have tried to get the values using onClick and onChange methods, but both of them returning the previous value. I understand that the internal state is set after calling this method. Is there any way to get the current selected value for a list preference so that I can pass the value to a binded service to reschedule a timer. Please help me ...

Here s the code I used:

   Preference.setOnPrefere开发者_开发问答nceChangeListener(new OnPreferenceChangeListener() {

            @Override
            public boolean onPreferenceChange(Preference preference, Object newValue) {
                // TODO Auto-generated method stub
                Context c = getApplicationContext();
                SharedPreferences sp = preference.getSharedPreferences();
                String period = sp.getString("prefKey", "defValue");
                return true;
            }
        });


Finally I have got the answer my self after rechecking the method.

There is an object called 'newValue' in the listener method. As the name says, its the new value selected :)

0

精彩评论

暂无评论...
验证码 换一张
取 消