是否可以在CalenderView中获取MONTH视图?

时间:2015-05-27 11:41:21

标签: android android-calendar

是否可以在calenderView中从显示的月份中获取月份的值?我已经尝试过......

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不再响应。

1 个答案:

答案 0 :(得分:0)

只有在选择了日期时才能获得回调但不能滚动...如果你想在回滚时更好地使用回调

    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);
        }
    };

希望这有助于满足您的要求......