setOnDayClickListener不适用于日历应用
calendarView=(CalendarView)findViewById(R.id.calendarView);
calendarView.setOnDayClickListener(new OnDayClickListener() {
@Override
public void onDayClick(EventDay eventDay) {
Calendar clickedDayCalendar = eventDay.getCalendar();
}
});
答案 0 :(得分:0)
CalendarView calendarView = findViewById(R.id.calendarView);
calendarView.setOnDateChangeListener(new CalendarView.OnDateChangeListener() {
@Override
public void onSelectedDayChange(@NonNull CalendarView calendarView, int year, int month, int date) {
}
});
尝试此代码。这将为您提供年,月和日
答案 1 :(得分:0)
希望您会发现这很有用。此代码将打开物料Callendar。您甚至可以使用setmaxdate和setmindate调整数据时间范围,否则将其忽略
final Calendar calendar = Calendar.getInstance();
int yy = calendar.get(Calendar.YEAR);
int mm = calendar.get(Calendar.MONTH);
int dd = calendar.get(Calendar.DAY_OF_MONTH);
final Calendar calendarMin = Calendar.getInstance();
calendarMin.set(yy, mm - 1, dd);
DatePickerDialog datePicker = new DatePickerDialog(ItemsOnDemandFilterActivity.this, new DatePickerDialog.OnDateSetListener() {
@Override
public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth) {
String date = String.valueOf(dayOfMonth) + "-" + String.valueOf(monthOfYear + 1)
+ "-" + String.valueOf(year);
startDateEditText.setText(date);
}
}, yy, mm, dd);
datePicker.getDatePicker().setMaxDate(System.currentTimeMillis());
datePicker.getDatePicker().setMinDate(calendarMin.getTimeInMillis());
datePicker.show();