我会使用 TimePickerFragment 来设置时间,它可以完美地工作。
我只想在用户单击“取消”按钮时执行一个操作。
不幸的是,到目前为止我还没有找到如何做到这一点。
这是我的代码:
创建对话框:
public void changeTime(int position) {
df = new TimePickerFragment();
df.setActivity(activity);
df.show(getSupportFragmentManager(), "timePicker");
positionItemTime = position;
}
当用户点击“set”时执行一个动作:
public void setTime(int hourOfDay, int minute) {
visibleCursorNotes.moveToPosition(positionItemTime);
int idSelectedRow = visibleCursorNotes.getInt(visibleCursorNotes.getColumnIndex("_id"));
String content = visibleCursorNotes.getString(visibleCursorNotes.getColumnIndex("content_note"));
String minuteString = "";
String hourOfDayString = "";
minuteString = "" + minute;
hourOfDayString = "" + hourOfDay;
if (minute < 10){
minuteString = "0" + minuteString;
}
if (hourOfDay < 10){
hourOfDayString = "0" + hourOfDayString;
}
String time = "" + hourOfDayString + ":" + minuteString ;
if (content.equals("")){
content = "add note ...";
}
nds.updateNote(idSelectedRow, content, time);
visibleCursorNotes = nds.getCursorUpdatedDatabaseForADate(visibleDate);
updateData();
visibleListView.setSelection(positionItemTime);
activity.managerOfSound("write note");
}
总结:想要捕捉点击取消按钮事件来执行一个动作。
谢谢。