我对时间选择器有疑问:我想创建一个自动计算工作时间的应用程序(如果我从早上 8 点开始并在 11:30 结束,结果我必须有 3:30)。
@Override
protected Dialog onCreateDialog(int id) {
switch (id) {
case TIME_DIALOG_ID:
return new TimePickerDialog(this, timePickerListener, hour, minute,false);
case TIME_DIALOG_ID2:
return new TimePickerDialog(this, timePickerListener2, hour1, minute1,false);
case TIME_DIALOG_ID3:
return new TimePickerDialog(this, timePickerListener3, hour, minute,false);
case TIME_DIALOG_ID4:
return new TimePickerDialog(this, timePickerListener4, hour, minute,false);
}
return null;
}
private TimePickerDialog.OnTimeSetListener timePickerListener = new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int selectedHour, int selectedMinute) {
hour = selectedHour;
minute = selectedMinute;
txtTime1.setText(new StringBuilder().append(padding_str(hour)).append(":").append(padding_str(minute)));
}
};
private TimePickerDialog.OnTimeSetListener timePickerListener4 = new TimePickerDialog.OnTimeSetListener() {
public void onTimeSet(TimePicker view, int selectedHour, int selectedMinute) {
hour4 = selectedHour;
minute4 = selectedMinute;
txtTime4.setText(new StringBuilder().append(padding_str(hour4)).append(":").append(padding_str(minute4)));
if (txtTime4 == null) {
hour4 = 0; hour3=0; minute4=0; minute3=0;
}
txtTimeresult1.setText(new StringBuilder().append(padding_str((hour1-hour)+(hour4-hour3))).append(":").append(padding_str((minute1-minute)+(minute4-minute3))));
}};