解决方案还没有找到,我已经花了几个小时来应对这个挑战。当你按下“今天”按钮时,我怎样才能得到一个日期?
想要获得按下“今天”按钮时显示的日期。并且,我们相信试图将信息添加到指定日期的屏幕显示的过程。
DatePickerDialog dpdialog = new DatePickerDialog(me, new OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int pickyear, int monthOfYear,
int dayOfMonth) {
}
}, year, month-1, day);
// Dialog(Positive Button)
dpdialog.setButton(
DialogInterface.BUTTON_POSITIVE,
"set",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Positive Button
// How to get the date set
String day = dpdialog.getDayOfMonth();
String month = dpdialog.getMonth() + 1;
String year = dpdialog.getYear();
}
}
);
// Dialog (Negative Button)
dpdialog.setButton(
DialogInterface.BUTTON_NEGATIVE,
"cancel",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Negative Button
}
}
);
// Dialog(Neutral Button)
dpdialog.setButton(
DialogInterface.BUTTON_NEUTRAL,
"today",
new DialogInterface.OnClickListener() {
public void onClick(DialogInterface dialog, int which) {
// Neutral Button
}
}
);
dpdialog.show();