How to use android seekbar to display time selection?

后端 未结 1 686
小鲜肉
小鲜肉 2021-01-15 19:49

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

1条回答
  •  礼貌的吻别
    2021-01-15 20:23

    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

    0 讨论(0)
提交回复
热议问题