how disable "autoscroll" hour on set value minute in time picker android
Asked Answered
T

2

6

I've a TimePicker on Android with two wheels. In the first I've hours in format 0 - 24, in the last I've minutes in interval step (generally 0 - 30).

When I change hour all work fine, when I set new value in minute timePicker change also the hours. there is a way in order to prevent it?

Here my code where I set values for the wheels:

    Class<?> classForid = Class.forName("com.android.internal.R$id");

    //picker ore
    Field fieldHour = classForid.getField("hour");

    hourPicker = (NumberPicker) timePicker.findViewById(fieldHour.getInt(null));
    hourPicker.setMinValue(startHour);
    hourPicker.setMaxValue(endHour);

    //picker minuti
    Field fieldMinute = classForid.getField("minute");

    minutePicker = (NumberPicker) timePicker.findViewById(fieldMinute.getInt(null));
    minutePicker.setMinValue(0);
    minutePicker.setMaxValue(numberFractionHour - 1);

    float pickerInterval = 60 / numberFractionHour;
    displayedMinutesValues = new ArrayList<String>();
    for (int i = 0; i < 60; i += pickerInterval)
        displayedMinutesValues.add(String.format("%02d", i));

    minutePicker.setDisplayedValues(displayedMinutesValues.toArray(new String[0])); 

Thanks in advance.

Toreutics answered 21/1, 2015 at 13:8 Comment(0)
G
3

Use code below to prevent hourPicker getting updated.

minutePicker.setOnValueChangedListener(null);
Gyrate answered 17/10, 2017 at 22:50 Comment(0)
V
0

I think, question and previous answer don't get a correct understanding, how to decide this problem.

Next part of code can answer this question fully

final TimePicker timePicker = dialoglayout.findViewById(R.id.timePicker);

Class<?> classForid = null;
try {
    classForid = Class.forName("com.android.internal.R$id");
    Field fieldMinute = classForid.getField("minute");
    NumberPicker minutePicker = (NumberPicker) timePicker.findViewById(fieldMinute.getInt(null));
    minutePicker.setOnValueChangedListener(null); //the method to stop autoscrolling
} catch (ClassNotFoundException | NoSuchFieldException | IllegalAccessException e) {
    e.printStackTrace();
}
Vegetarianism answered 8/9, 2021 at 6:26 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.