How to use android seekbar to display time selection?

蹲街弑〆低调 提交于 2019-12-01 14:03:16

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.

Example 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.
  }
});

hope this helps

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