如何使用Android搜索栏来显示时间的选择? [英] How to use android seekbar to display time selection?

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

问题描述

我曾尝试搜索栏的正常任务,以显示从1到12的时间,但我有一点不同的要求。

I have tried seekbar normal task to display the time from 1 to 12 but I have little different requirement.

请一些身体可以帮助我获得搜索栏显示的值完全是这样的。

please some body can help me to get seekbar show value exactly like this.

推荐答案

您的搜索栏具有最小到最大的范围。您必须确定您所需要的范围。例如你想选择最新与寻求从0:00栏23:59为15分钟的一步。因此,你需要用最小= 0,最大值= 24 * 4的范围吧。
当你的搜索栏被改变,你需要计算实际选择的时间。对于这一点,你可以得到搜索栏的进展,并繁衍到15分钟。你会得到选择分钟。

your seek bar have a range from min to max. You must define what range you need. For example you want to choose date with seek bar from 0:00 to 23:59 with step of 15 minutes. So you need range bar with min = 0 and max = 24 * 4. When your seek bar is changed you need to calculate actual selected time. For that, you can get SeekBar progress and multiply it to 15 minutes. And you will get selected minutes.

举例code:

seekBar.setMax(24 * 4); //24 hours and 4 step in one hour.

seekBar.setOnSeekBarChangeListener(new OnSeekBarChangetListener() {
  public void onProgressChanged (SeekBar seekBar, int progress, boolean fromUser) {
     int hours = progress / 4; // it will return hours.
     int minutes = (progress % 4) * 15; // here will be minutes.
  }
});

希望这有助于

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

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