68 lines
1.7 KiB
Java
68 lines
1.7 KiB
Java
|
|
package com.xscm.moduleutil.widget;
|
||
|
|
|
||
|
|
import android.content.Context;
|
||
|
|
import android.util.AttributeSet;
|
||
|
|
import android.widget.LinearLayout;
|
||
|
|
import android.widget.NumberPicker;
|
||
|
|
|
||
|
|
public class WheelTimePicker extends LinearLayout {
|
||
|
|
|
||
|
|
private NumberPicker hourPicker, minutePicker, secondPicker;
|
||
|
|
|
||
|
|
public WheelTimePicker(Context context) {
|
||
|
|
this(context, null);
|
||
|
|
}
|
||
|
|
|
||
|
|
public WheelTimePicker(Context context, AttributeSet attrs) {
|
||
|
|
super(context, attrs);
|
||
|
|
init(context);
|
||
|
|
}
|
||
|
|
|
||
|
|
private void init(Context context) {
|
||
|
|
setOrientation(HORIZONTAL);
|
||
|
|
|
||
|
|
hourPicker = new NumberPicker(context);
|
||
|
|
minutePicker = new NumberPicker(context);
|
||
|
|
secondPicker= new NumberPicker(context);
|
||
|
|
|
||
|
|
LayoutParams params = new LayoutParams(0, LayoutParams.WRAP_CONTENT, 1);
|
||
|
|
hourPicker.setLayoutParams(params);
|
||
|
|
minutePicker.setLayoutParams(params);
|
||
|
|
secondPicker.setLayoutParams(params);
|
||
|
|
|
||
|
|
addView(hourPicker);
|
||
|
|
addView(minutePicker);
|
||
|
|
addView(secondPicker);
|
||
|
|
|
||
|
|
// 设置小时范围
|
||
|
|
hourPicker.setMinValue(0);
|
||
|
|
hourPicker.setMaxValue(23);
|
||
|
|
|
||
|
|
// 设置分钟范围
|
||
|
|
minutePicker.setMinValue(0);
|
||
|
|
minutePicker.setMaxValue(59);
|
||
|
|
|
||
|
|
// 秒范围
|
||
|
|
secondPicker.setMinValue(0);
|
||
|
|
secondPicker.setMaxValue(59);
|
||
|
|
}
|
||
|
|
|
||
|
|
public void init(int hour, int minute, int second) {
|
||
|
|
hourPicker.setValue(hour);
|
||
|
|
minutePicker.setValue(minute);
|
||
|
|
secondPicker.setValue(second);
|
||
|
|
}
|
||
|
|
|
||
|
|
public int getHour() {
|
||
|
|
return hourPicker.getValue();
|
||
|
|
}
|
||
|
|
|
||
|
|
public int getMinute() {
|
||
|
|
return minutePicker.getValue();
|
||
|
|
}
|
||
|
|
|
||
|
|
public int getSecond() {
|
||
|
|
return secondPicker.getValue();
|
||
|
|
}
|
||
|
|
}
|