gpt4 book ai didi

android - 如何在时间选择器中设置最大和最小时间?

转载 作者:太空宇宙 更新时间:2023-11-03 11:11:23 30 4
gpt4 key购买 nike

我有中午 12:00 到中午 12:00 的时间间隔。我想在时间选择器对话框中设置这个时间间隔。在时间选择器中禁用中午 12:00 之前和中午 12:00 之后的时间。我不知道如何在时间选择器对话框中设置时间。任何人都可以帮助我解决这个问题。

时间选择器

 private void showTimePicker(){

Time_picker time = new Time_picker();

Bundle args = new Bundle();
args.putInt("hours", c.get(Calendar.HOUR_OF_DAY)+2);
args.putInt("minute", c.get(Calendar.MINUTE)+30);

time.setArguments(args);
time.setCallBack(ontime);
time.show(((FragmentActivity) getActivity()).getSupportFragmentManager(), "Time Picker");

}

OnTimeSetListener ontime = new OnTimeSetListener() {

@Override
public void onTimeSet(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub

try {
String _24HourTime = String.valueOf(hourOfDay)+":"+String.valueOf(minute);
SimpleDateFormat _24HourSDF = new SimpleDateFormat("HH:mm");
SimpleDateFormat _12HourSDF = new SimpleDateFormat("hh:mm a");
Date _24HourDt = _24HourSDF.parse(_24HourTime);
et_time.setText(_12HourSDF.format(_24HourDt));
} catch (Exception e) {
e.printStackTrace();
}
}
};

时间选择器对话框 fragment

public class Time_picker extends DialogFragment{

OnTimeSetListener ontimeSet;

public Time_picker() {

}

public void setCallBack(OnTimeSetListener ontime) {

ontimeSet = ontime;

}

private int hours, minute, pm;
@Override
public void setArguments(Bundle args) {
super.setArguments(args);
hours = args.getInt("hours");
minute = args.getInt("minute");
}

@Override
public Dialog onCreateDialog(Bundle savedInstanceState) {

TimePickerDialog _time = new TimePickerDialog(getActivity(), ontimeSet, hours, minute, false){

@Override
public void onTimeChanged(TimePicker view, int hourOfDay, int minute) {
// TODO Auto-generated method stub


}
};

return _time;
}
}

最佳答案

我不确定您是否可以更改时间选择器中显示的时间值,但是您可以为时间选择器更改时创建一个事件监听器,它将拒绝任何不在您想要的时间间隔内的值

关于android - 如何在时间选择器中设置最大和最小时间?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24029949/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com