我正在使用 DatePickerDialog
选择日期。当月份从一周的最后一天开始,并且有 31 天时,不显示该月的最后一天。例如 2019 年 12 月从星期日开始,不显示日期 30 和 31。
我尝试设置 datepickerdialog.setFirstDayOfWeek(Calender.SUNDAY)
。从星期六开始的几个月里,这个问题将保持不变。
dpd = DatePickerDialog.newInstance(
JobAssignedActivity.this,
now.get(Calendar.YEAR),
now.get(Calendar.MONTH),
now.get(Calendar.DAY_OF_MONTH)
);
Calendar minDate = Calendar.getInstance();
dpd.setMinDate(minDate);
dpd.setFirstDayOfWeek(Calendar.SUNDAY);
dpd.setAccentColor(ContextCompat.getColor(this, R.color.mdtp_accent_color));
dpd.show(getFragmentManager(), "Datepickerdialog");
最佳答案
试试这个,它会给出正确的输出
DatePickerDialog.OnDateSetListener onDateSetListener = new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear,int dayOfMonth) {
Log.v("onDateSet",dayOfMonth+"/"+(monthOfYear+1)+"/"+year);
}
};
final Calendar cal = Calendar.getInstance();
new DatePickerDialog(YourActivity.this, onDateSetListener,
cal.get(Calendar.YEAR), cal.get(Calendar.MONTH),
cal.get(Calendar.DAY_OF_MONTH)).show();
关于java - DatePickerDialog 中未显示该月的最后日期,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58212252/