badoualy / datepicker-timeline

An infinite scrolling timeline to pick a date
MIT License
464 stars 71 forks source link

Can't use setOnDateSelectedListener in kotlin #36

Closed JKhanh closed 4 years ago

JKhanh commented 4 years ago

When I call setOnDateSelectedListener I get an error "Expresstion cannot be invoke as a function. The function invoke() is not found" My code: datePicker.onDateSelectedListener(object: DatePickerTimeline.OnDateSelectedListener{ override fun onDateSelected(year: Int, month: Int, day: Int, index: Int) { calendar.set(year, month, day) viewModel.getDiaryByPriority(calendar, "objective") } })

sam3961 commented 3 years ago

Use this way

datePicker.setOnDateSelectedListener{ year, month, day, index -> var strDay = day.toString() var strMonth = (month+1).toString() if (strMonth.toInt()<10) strMonth = "0$strMonth" if (day<10) strDay = "0$day" textView.text = strDay+"-"+strMonth+"-"+year.toString() popupWindow.dismiss() }