How to set time range using seekbar

亡梦爱人 提交于 2019-12-02 03:06:12

问题


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 selected, and some other extras as well.

As at the moment the seekbar can select range between numbers/digits but cannot be used for actual time range selection in 12 hours system like 12am-3pm.

I am tring to achieve the above but with no success.

After looking through stackoverflow i stumbled again at a similar issue but cannot seem to reuse or implement for my case.

Similarly a github repo promised to solve the issue but after running the class, i simply cannot see the changes.

Any suggestions will be highly appreciated!

Here is the class to modify.

How i used it:

RangeSeekBar rangeSeekBar = (RangeSeekBar) findViewById(R.id.seekbar);
        rangeSeekBar.setRangeValues(15, 90);
        rangeSeekBar.setSelectedMinValue(20);
        rangeSeekBar.setSelectedMaxValue(88);

回答1:


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);


来源:https://stackoverflow.com/questions/36869158/how-to-set-time-range-using-seekbar

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!