向下滑动时 CalendarView 关闭

CalendarView close when I slide down

我正在尝试设置我的日历视图,但遇到了问题。我设置了 android 标准 CalendarView,它似乎运行良好,但有一个问题。当我向下滑动查看下个月并选择实际日期时,视图关闭。有人可以帮我解决这个问题吗?我想这不是很难解决,但我不能,我被卡住了。

我在这里做了一切: http://www.thaicreate.com/mobile/android-calendarview.html(第二个例子) 甚至在这里: http://androiddhina.blogspot.in/2015/04/android-calender-view.html

这是标准实现。

确实,当用户选择新日期或滚动到其他月份时都会调用侦听器。

解决方法如下:

public class CalendarViewActivity extends Activity {

    private static final String TAG = CalendarViewActivity.class.getSimpleName();

    private int mYear;
    private int mMonth;
    private int mDay;

    private long initialDate;

    @Override protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        CalendarView calendar = new CalendarView(this);
        calendar.setOnDateChangeListener(mDateSetListener);

        // Save initial date of calendar
        initialDate = calendar.getDate();

        setContentView(calendar);
    }

    private CalendarView.OnDateChangeListener mDateSetListener = new CalendarView.OnDateChangeListener() {
        @Override public void onSelectedDayChange(CalendarView view, int year, int monthOfYear, int dayOfMonth) {

            if (view.getDate() == initialDate) {
                // Listener called but user have not selected date
                return;
            }

            mYear = year;
            mMonth = monthOfYear;
            mDay = dayOfMonth;

            view.getDate();

            String selectedDate = new StringBuilder().append(mMonth + 1).append("-").append(mDay).append("-")
                    .append(mYear).append(" ").toString();

            Bundle b = new Bundle();
            b.putString("dateSelected", selectedDate);

            //Add the set of extended data to the intent and start it
            Intent intent = new Intent();
            intent.putExtras(b);
            setResult(RESULT_OK,intent);
            finish();
        }
    };
}