在您打开对话框之前将当前时间传递给 updateTimer() 函数,例如:
mTimePickerDialog = new TimePickerDialog(this, null, 0, 0, false);
Button button = (Button) findViewById(R.id.button1);
button.setOnClickListener(new OnClickListener() {
public void onClick(View view) {
Calendar calendar = Calendar.getInstance();
mTimePickerDialog.updateTime(calendar.get(Calendar.HOUR_OF_DAY), calendar.get(Calendar.MINUTE));
mTimePickerDialog.show();
}
});
** 添加 **
我相信您想像这样覆盖 onPrepareDialog() 函数:
@Override
protected void onPrepareDialog (int id, Dialog dialog, Bundle args) {
super.onPrepareDialog(id, dialog, args);
if(id != DATE_DIALOG_ID) {
final Calendar c = Calendar.getInstance();
((TimePickerDialog) dialog).updateTime(c.get(Calendar.HOUR_OF_DAY), c.get(Calendar.MINUTE));
}
}