gpt4 book ai didi

android - 如何获取android中DatePickerDialog中设置的日期?

转载 作者:行者123 更新时间:2023-11-29 00:40:30 24 4
gpt4 key购买 nike

还没有找到解决方案,我已经花了几个小时来解决这个问题。我怎样才能得到一个日期,看看你什么时候按下“今天”按钮?

想要获取按下“今天”按钮时显示的日期。并且,我们相信尝试将信息添加到指定日期的屏幕显示的过程。

    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();

最佳答案

在外部类中定义的变量对于内部类/内联方法是可见的,所以你可以这样做:

private String day;
private String month;
private String year;

DatePickerDialog dpdialog = new DatePickerDialog(me, new OnDateSetListener() {

@Override
public void onDateSet(DatePicker view, int pickyear, int monthOfYear, int dayOfMonth) {
// you have the picked year/month/day here.
// For example:
day = String.valueOf(dayOfMonth);
month = String.valueOf(monthOfYear);
year = String.valueOf(pickyear);
}

}, year, month-1, day);

关于android - 如何获取android中DatePickerDialog中设置的日期?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9677721/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com