khacpv / Calendar-Day-View

Calendar Day View is an android library to display calendars day view within the app. It supports custom styling.
MIT License
56 stars 34 forks source link

onEventClick and onEventViewClick not fired #23

Open reuniware opened 4 years ago

reuniware commented 4 years ago

Hello ! I'm trying to use your component in a Kotlin project but I cannot have these events fired when I click anywhere in the visible control... Here is the Kotlin code :

package com.reuniware.beautylogic

import android.os.Bundle
import android.util.Log
import android.view.View
import androidx.appcompat.app.AppCompatActivity
import com.framgia.library.calendardayview.EventView
import com.framgia.library.calendardayview.EventView.OnEventClickListener
import com.framgia.library.calendardayview.data.IEvent
import com.framgia.library.calendardayview.decoration.CdvDecorationDefault
import kotlinx.android.synthetic.main.activity_main.*

class MainActivity : AppCompatActivity() {

    val events = ArrayList<IEvent>()

    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_main)

        (dayView.decoration as CdvDecorationDefault).setOnEventClickListener(
            object : OnEventClickListener {
                override fun onEventClick(view: EventView, data: IEvent) {
                    Log.e("TAG", "onEventClick:" + data.name)
                }

                override fun onEventViewClick(
                    view: View,
                    eventView: EventView,
                    data: IEvent
                ) {
                    Log.e("TAG", "onEventViewClick:" + data.name)
                    if (data is IEvent) { // change event (ex: set event color)
                        dayView.setEvents(events)
                    }
                }
            })

        dayView.setEvents(events)
    }
}

And here is the code of the XML layout file :

<?xml version="1.0" encoding="utf-8"?>
<androidx.constraintlayout.widget.ConstraintLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    tools:context=".MainActivity">

    <ScrollView
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:layout_marginTop="24dp"
        android:layout_marginBottom="24dp"
        android:layout_marginStart="24dp"
        android:layout_marginEnd="24dp">
        <com.framgia.library.calendardayview.CalendarDayView
            android:id="@+id/dayView"
            android:layout_width="match_parent"
            android:layout_height="wrap_content" />
    </ScrollView>

</androidx.constraintlayout.widget.ConstraintLayout>

Thanks in advance !