How to set time range using seekbar

后端 未结 1 1581
野性不改
野性不改 2021-01-21 15:49

I stumbled upon this library by Anothem. Basically it provides a SeekBar similar to the default Android one, but with two thumb controls allowing a range to be sele

相关标签:
1条回答
  • 2021-01-21 16:19

    Why are you setting the range values from 15 to 90? If you are trying to depict time, you should set the range values as:

    rangeSeekBar.setRangeValues(0,24 * SMALLEST_HOUR_FRACTION);
    

    where SMALLEST_HOUR_FRACTION is the smallest block of time you can select (2 to select every half hour, 4 for every quarter hour (15 minutes), 60 for every minute).

    Then, to determine the time the user selected, use:

    int minHour = rangeSeekBar.getSelectedMinValue() / SMALLEST_HOUR_FRACTION;
    int minMinute = SMALLEST_HOUR_FRACTION * (rangeSeekBar.getSelectedMinValue() % SMALLEST_HOUR_FRACTION);
    int maxHour = rangeSeekBar.getSelectedMaxValue() / SMALLEST_HOUR_FRACTION;
    int maxMinute = SMALLEST_HOUR_FRACTION * (rangeSeekBar.getSelectedMaxValue() % SMALLEST_HOUR_FRACTION);
    
    0 讨论(0)
提交回复
热议问题