开发者

get the selected preference value in android

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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜