gregkorossy/Android-Support-Preference-V7-Fix

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

PokerAsh opened this issue · 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?

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;