Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
PokerAsh opened this issue Oct 10, 2018 · 1 comment

Comments

@PokerAsh
Copy link

PokerAsh commented Oct 10, 2018

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?

@George-Ogden
Copy link

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;

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants