如何使用搜索栏设置时间范围 [英] How to set time range using seekbar

查看:83
本文介绍了如何使用搜索栏设置时间范围的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我偶然发现了 Anothem的这个库.基本上,它提供的 SeekBar 与默认的Android类似,但具有两个拇指控件,可以选择一个范围,以及其他一些功能.

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.

目前,可以在数字/数字之间选择范围,但不能用于中的实际 time 范围选择12小时系统,例如 12 am-3pm .

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.

查看了stackoverflow之后,我再次迷失在

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

类似地,一个 github存储库承诺解决该问题,但是在运行该类之后,我根本看不到变化.

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

任何建议将不胜感激!

此处是要修改的类.

我如何使用它:

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

推荐答案

为什么将范围值设置为15到90?如果您想描绘时间,则应将范围值设置为:

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

其中 SMALLEST_HOUR_FRACTION 是您可以选择的最小时间段( 2 每半小时选择一次, 4 每四分之一小时选择(15分钟),每分钟 60 .

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

这篇关于如何使用搜索栏设置时间范围的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆