1

I am trying create a calendar view where the user selects a day from a calendar and then displays the day month and year.

val calendar = findViewById(R.id.calendarView)
calendar.SetOnDateChangeListener(object : calendar.onDateChangeListener() {
    fun onSelectedDayChange(@NonNull calendarView: calender, i: Int, il: Int, i2: Int) {
        val date = i + "/" + il + "/" + i2
        val intent = Intent(this@CalenderActivity, MainActivity::class.java)
        intent.putExtra("date", date)
        startActivity(intent)
    }
}

I get this error message:

Unresolved reference: calendar at the SetOnDateChangeListener.

What am I doing wrong?

ordonezalex
  • 2,645
  • 1
  • 20
  • 33
  • Possible duplicate of [Kotlin unresolved reference in IntelliJ](https://stackoverflow.com/questions/31712046/kotlin-unresolved-reference-in-intellij) – Léa Gris Jul 24 '19 at 21:56

1 Answers1

2

CalendarView has no SetOnDateChangeListener method. You have to write setOnDateChangeListener instead of SetOnDateChangeListener. But you have many other errors in this code. I think that final code should look like this:

val calendar = findViewById<CalendarView>(R.id.calendarView)
calendar.setOnDateChangeListener(CalendarView.OnDateChangeListener { _, i, il, i2 ->
    val date = "$i/$il/$i2"
    val intent = Intent(this@CalenderActivity, MainActivity::class.java)
    intent.putExtra("date", date)
    startActivity(intent)
}
Andrei Tanana
  • 7,932
  • 1
  • 27
  • 36