Android-Support-Preference-V7-Fix icon indicating copy to clipboard operation
Android-Support-Preference-V7-Fix copied to clipboard

timePickerPreference.setOnPreferenceChangeListener((preference, newValue) gives me null

Open PokerAsh opened this issue 7 years ago • 1 comments

Hello,

After migrating to androidx I've got this weird error. Whenever, I use

timePickerPreference.setOnPreferenceChangeListener((preference, newValue) -> {
            if(preference instanceof TimePickerPreference) {
                Log.d(TAG, "onPreferenceChange: ZZZ " + newValue.toString());
                Log.d(TAG, "onPreferenceChange: ZZZ " + ((TimePickerPreference) preference).getHourOfDay() + ":" + ((TimePickerPreference) preference).getMinute()));
                Log.d(TAG, "onPreferenceChange: ZZZ " + ((TimePickerPreference) preference).getTime());
                return true;
            }
            return false;
        });
  1. newValue.toString() doesn't give me any formatted HH:mm as mentioned in wiki.
  2. ((TimePickerPreference) preference).getHourOfDay() + ":" + ((TimePickerPreference) preference).getMinute()) gives me -1:-1
  3. ((TimePickerPreference) preference).getTime() gives me null.

However whenever I press OK, after picking the time, it puts on the field summary correct time. Am I doing something, wrong or is there some issue going on?

PokerAsh avatar Oct 10 '18 10:10 PokerAsh

This is an issue I have too - the preference returns the previous value, rather than the current one. However, this fix should allow you to get the time:

int hour = ((TimePickerPreference.TimeWrapper) newValue).hour;
int minute =  ((TimePickerPreference.TimeWrapper) newValue).minute;

George-Ogden avatar Apr 03 '21 17:04 George-Ogden