当我单击它时,我有两个edittext,会弹出一个timepickerdialog,并且时间将在edittext中设置,因为我的代码是,
int TIME_PICKER_ID = 1,hour,minute,flag;
edittext_starttime.setOnClickListener(this);
edittext_endtime.setOnClickListener(this);
final Calendar c = Calendar.getInstance();
hour = c.get(Calendar.HOUR_OF_DAY);
minute = c.get(Calendar.MINUTE);
@Override
public void onClick(View v) {
if(v.getId() == R.id.editText_starttime_stsa){
flag = 1;
showDialog(TIME_PICKER_ID);
}//editText_starttime_stsa
if(v.getId() == R.id.editText_endtime_stsa){
flag = 2;
showDialog(TIME_PICKER_ID);
}//editText_endtime_stsa
if(v.getId() == R.id.button_create_stsa){
onCreateAlert();
}//button_create_susa
}
@Override
protected Dialog onCreateDialog(int id) {
switch(id){
case 1:
return new TimePickerDialog(this, timePickerListener, 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;
updateDisplay(hour,minute);
}
};
private void updateDisplay(int hour, int minute) {
if(flag==1){
edittext_starttime.setText(new StringBuilder().append(pad(hour)).append(":").append(pad(minute)));
}else if(flag==2){
edittext_endtime.setText(new StringBuilder().append(pad(hour)).append(":").append(pad(minute)));
}
}
private static String pad(int c) {
if (c >= 10)
return String.valueOf(c);
else
return "0" + String.valueOf(c);
}
我想在我写过查询的 sqlite 数据库中插入 start_time 和 end_time,
String query = "insert into Status_Master(status_id, status_name, status_description, timewindow_start, timewindow_end) values("+status_id+",'"+status_name+"','"+status_desc+"',time('"+start_time+"'),time('"+end_time+"'))";
但我收到错误。这是在数据库中插入时间的正确方法吗?