我知道Calendar类中设置的日期是从0(即1月)开始的,因此2月为1。
但是我面临问题,这是我的代码:
private void setDatePicker() {
int value = datePicker.getValue();
int month = monthPicker.getValue();
int year = yearPicker.getValue();
Calendar calendar = Calendar.getInstance();
calendar.set(Calendar.MONTH,1);//done static for testing purpose
calendar.set(Calendar.YEAR,year);
Date date = new Date(calendar.getTimeInMillis());
int min =calendar.getActualMinimum(Calendar.DAY_OF_MONTH);
int max =calendar.getActualMaximum(Calendar.DAY_OF_MONTH);
datePicker.setMinValue(calendar.getActualMinimum(Calendar.DAY_OF_MONTH));
datePicker.setMaxValue(calendar.getActualMaximum(Calendar.DAY_OF_MONTH));
if(value>0)
datePicker.setValue(value);
//implement array string to number picker
datePicker.setWrapSelectorWheel(false);
//disable soft keyboard
datePicker.setDescendantFocusability(NumberPicker.FOCUS_BLOCK_DESCENDANTS);
}
我正面临问题时,将静态设置为每月1个值进行测试。因此,我从设置中获得的价值是在日历中前进。这是不正常的行为,是什么原因引起的?