Android 是否可以在CalendarView中获取视图月份?
是否可以从日历视图中显示的月份中获取月份值?我已经试过了Android 是否可以在CalendarView中获取视图月份?,android,android-calendar,Android,Android Calendar,是否可以从日历视图中显示的月份中获取月份值?我已经试过了 calenderView1.setOnDateChangeListener(new OnDateChangeListener() { @Override public void onSelectedDayChange(CalendarView view, int year, int month, int day) { SimpleDateForma
calenderView1.setOnDateChangeListener(new OnDateChangeListener() {
@Override
public void onSelectedDayChange(CalendarView view, int year,
int month, int day) {
SimpleDateFormat df = new SimpleDateFormat("MMMM");
String result = df.format(month);
System.out.println(" MONTH IS " + result);
monthshowing = result;
System.out.println(" MONTH IS NOW " + monthshowing);
button1.setText(monthshowing);
}
});
但12月又是一个月。此外,当我继续滚动时,12月仍然存在,OnDateChangeListener不再响应。仅当选择日期时,您将收到回调,但不用于滚动。。如果您想在滚动时更好地使用回调
DatePickerDialog p = new DatePickerDialog(this,null,2015,4,28){
@Override
public void onDateChanged(DatePicker view, int year, int month, int day) {
//this method will called when you scroll
//do your stuff over here.
super.onDateChanged(view, year, month, day);
}
};
希望这对您的需求有所帮助…仅当您从CalenderView中选择日期时才更新日期。参观