【发布时间】:2020-11-18 09:15:36
【问题描述】:
主要活动
{
date = findViewById(R.id.add_date);
dueDate = findViewById(R.id.add_dueDate);
final Calendar calendar = Calendar.getInstance();
date.setOnClickListener(v -> {
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
day = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(addScreen.this, (view, year, month, dayOfMonth) -> date.setText(SimpleDateFormat.getDateInstance().format(calendar.getTime())), year, month, day);
datePickerDialog.show();
});
dueDate.setOnClickListener(v -> {
year = calendar.get(Calendar.YEAR);
month = calendar.get(Calendar.MONTH);
day = calendar.get(Calendar.DAY_OF_MONTH);
DatePickerDialog datePickerDialog = new DatePickerDialog(addScreen.this, (view, year, month, dayOfMonth) -> dueDate.setText(SimpleDateFormat.getDateInstance().format(calendar.getTime())), year, month, day);
datePickerDialog.show();
});
}
此代码有问题,我无法选择。 我让日历(onClick 提示)选择日期,但即使我选择过去、现在或未来的日期,它总是在编辑文本中返回当前(今天的)日期。
【问题讨论】:
标签: java android android-studio date kotlin