Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 251
iNiko84 Avatar asked Jan 21 '15 13:01

iNiko84


1 Answers

Use code below to prevent hourPicker getting updated.

minutePicker.setOnValueChangedListener(null);
like image 83
Tristan Zhou Avatar answered Nov 03 '22 09:11

Tristan Zhou