无法向CalendarView事件添加侦听器

时间:2022-08-31 23:11:48

There is the following code:

有以下代码:

    final CalendarView calendarView=(CalendarView)layout.findViewById(R.id.calendarView);
    calendarView.setClickable(true);
    calendarView.setOnClickListener(new OnClickListener() {

            @Override
            public void onClick(View v) {
                Toast.makeText(getActivity(), "Click", Toast.LENGTH_LONG).show();
            }

    });
    calendarView.setOnTouchListener(new OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {
                Toast.makeText(getActivity(), "Touch", Toast.LENGTH_LONG).show();
                return false;
            }

    });
    calendarView.setOnLongClickListener(new OnLongClickListener() {

            @Override
            public boolean onLongClick(View v) {
                Toast.makeText(getActivity(), "Long click", Toast.LENGTH_LONG).show();
                return false;
            }

    });

I haven't got any messages yet. I need to set listeners for click by Date. I know about OnDateChangeListener, but it will work only if user changes the date, but if user clicks by the same date I haven't got any messages. Please tell me, how can I set listeners for click by dates. Thank you in advance.

我还没有收到任何消息。我需要设置每日点击的监听器。我知道OnDateChangeListener,但它只有在用户更改日期时才有效,但如果用户点击相同的日期我没有收到任何消息。请告诉我,如何设置听众按日期点击。先感谢您。

1 个解决方案

#1


0  

The native Calendar is crappy IMO. It seems like clicking on any of the date won't fire any events at all. However the onClick and onLongClick event will be fired if you click near the border of the calendar.

原生日历是糟糕的IMO。似乎点击任何一个日期都不会触发任何事件。但是,如果单击日历边框附近,将触发onClick和onLongClick事件。

#1


0  

The native Calendar is crappy IMO. It seems like clicking on any of the date won't fire any events at all. However the onClick and onLongClick event will be fired if you click near the border of the calendar.

原生日历是糟糕的IMO。似乎点击任何一个日期都不会触发任何事件。但是,如果单击日历边框附近,将触发onClick和onLongClick事件。