Bigkoo / Android-PickerView

This is a picker view for android , support linkage effect, timepicker and optionspicker.(时间选择器、省市区三级联动)
Apache License 2.0
13.44k stars 3.45k forks source link

TimePickerView 设置时间间隔 #405

Open lucifer222 opened 7 years ago

lucifer222 commented 7 years ago

请问TimePickerView是否可以设置时间间隔,比如分钟间隔5分钟显示

yangjinke commented 7 years ago

我也遇到这个问题了。请问你解决没,无法直接设置时间间隔,我们是需求是5分钟

yangjinke commented 7 years ago

我用条件选择器解决了,只显示时分,5分钟一条数据 ,写死了

xiaorongbin commented 6 years ago

大佬们,你们解决了到是给个可行的解决方案啊……

K-Kiko commented 4 years ago

条件选择器的限制太多了(例如:目前labels只能是3个),不合适,最简单的就是从dialog获取MinuteWheelView的实例再重新设置其Adapter就可以了

val dialog = pvTime.dialog
val minuteWheelView = dialog.findViewById<WheelView>(R.id.min)
minuteWheelView.adapter = HaloMinuteWheelViewAdapter(mPickerMinutes)
public class HaloMinuteWheelViewAdapter implements WheelAdapter {
    private int[] minutes;

    public HaloMinuteWheelViewAdapter(int[] minutes) {
        this.minutes = minutes;
    }

    @Override
    public Object getItem(int index) {
        return minutes[index];
    }

    @Override
    public int getItemsCount() {
        return minutes.length;
    }

    @Override
    public int indexOf(Object o) {
        try {
            return (int) o;
        } catch (Exception e) {
            return -1;
        }
    }
}

不过这里会有的一个问题,选择后的数据minute其实是mPickerMinutes的position,最后我在回调时对返回的date数据进行转换就行了

val timeSelectListener = OnTimeSelectListener { data: Date?, _ ->
      run {
             data?.minutes = mPickerMinutes.get(data?.minutes ?: 0)
      }
 }
princekin-f commented 4 years ago

嫌拖本地修改麻烦的,可以直接使用这个:https://github.com/princekin-f/Android-PickerView

效果如下: