【发布时间】:2013-09-16 22:02:23
【问题描述】:
我有下一个代码:
dateDisplay1.setOnClickListener(new OnClickListener() {
@SuppressWarnings("deprecation")
public void onClick(View v) {
option = 1;
showDialog(DATE_DIALOG_ID);
}
});
还有 onCreateDialog 函数:
protected Dialog onCreateDialog(int id) {
Calendar cal = Calendar.getInstance();
switch (id) {
case DATE_DIALOG_ID:
return new DatePickerDialog(this, dayDate, cal.get(Calendar.YEAR), cal.get(Calendar.MONTH), cal.get(Calendar.DAY_OF_MONTH));
case TIME_DIALOG_ID:
return new TimePickerDialog(this, timeDate, cal.get(Calendar.HOUR_OF_DAY), cal.get(Calendar.MINUTE), false);
}
return null;
}
我想要做的是将已弃用的 showDialog() 调整为 DialogFragment,但没有成功。下面的代码有效,但它不是最佳实践。所以我想更正代码。
你将如何实现它?
【问题讨论】:
标签: android-dialog android-datepicker