gpt4 book ai didi

android - 重新选择日期选择器后的日期选择器对话框显示当前日期

转载 作者:行者123 更新时间:2023-11-29 14:31:49 24 4
gpt4 key购买 nike

我试图在再次选择时在日期选择器对话框中显示所选日期。

这是我尝试过的。

 signup.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View v) {


Calendar mcurrentDate=Calendar.getInstance();
year=mcurrentDate.get(Calendar.YEAR);
month=mcurrentDate.get(Calendar.MONTH);
day=mcurrentDate.get(Calendar.DAY_OF_MONTH);

DatePickerDialog mDatePicker=new DatePickerDialog(CreateAccountActivity.this, new OnDateSetListener()
{
@Override
public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday)
{
year = selectedyear;
month = selectedmonth;
day = selectedday;
signup.setText(new StringBuilder().append(year).append("-").append(month+1).append("-").append(day));
}
},year, month, day);
mDatePicker.setTitle("Please select date");
mDatePicker.getDatePicker().setMaxDate(System.currentTimeMillis());
mDatePicker.show();


}
});

但问题是当我再次选择我的约会对象时。它显示当前日期。我想在对话框中显示选定的日期。

最佳答案

我已经解决了答案...

答案在这里....

public void onClick(View v) {

if (year == 0 || month == 0 || day == 0) {
Calendar mcurrentDate=Calendar.getInstance();
year=mcurrentDate.get(Calendar.YEAR);
month=mcurrentDate.get(Calendar.MONTH);
day=mcurrentDate.get(Calendar.DAY_OF_MONTH);
}

DatePickerDialog mDatePicker=new DatePickerDialog(CreateAccountActivity.this, new OnDateSetListener()
{
@Override
public void onDateSet(DatePicker datepicker, int selectedyear, int selectedmonth, int selectedday)
{
year = selectedyear;
month = selectedmonth;
day = selectedday;
signup.setText(new StringBuilder().append(year).append("-").append(month+1).append("-").append(day));
}
},year, month, day);
mDatePicker.setTitle("Please select date");
mDatePicker.getDatePicker().setMaxDate(System.currentTimeMillis());
mDatePicker.show();

我关注了页面 DatePickerDialog always opens the current date

并阅读评论并感谢@Andrew T :)

关于android - 重新选择日期选择器后的日期选择器对话框显示当前日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23195919/

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