Hello
The layout have single DatePicker widget with datePicker id
I wonder about usage of synthetic references generated by kotlin-android-extensions
As I understand I should have access to datePicker reference anywere in the class (especially Location1, and Location2). Android Studio see references correctly (no errors, I can properly jump to declaration, I have proper code hit), but when running this peace of code I got error:
java.lang.IllegalArgumentException: Parameter specified as non-null is null
import android.app.Dialog
import android.os.Bundle
import android.support.v4.app.DialogFragment
import android.support.v7.app.AlertDialog
import android.view.LayoutInflater
import kotlinx.android.synthetic.main.dialog_date.*
class DatePickerFragment() : DialogFragment() {
// private lateinit var datePicker: DatePicker
override fun onCreateDialog(savedInstanceState: Bundle?): Dialog {
val v = LayoutInflater.from(activity)
.inflate(R.layout.dialog_date, null)
// datePicker = v.findViewById(R.id.datePicker) as DatePicker
var alert = AlertDialog.Builder(activity)
// Location1: cannot access datePicker error here unless i uncomment findViewById
with(alert)
{
setView(v)
setTitle(R.string.date_picker_title)
setPositiveButton(android.R.string.ok) { dialog, witchButton -> onPositiveClick() }
}
return alert.create()
}
private fun onPositiveClick() {
println(datePicker) // Location2: cannot access datePicker error here
}
}
This works fine when I uncomment findViewById and datePicker variable declaration lines, but I believe this should work without this (as I understood this is the job kotlin android extensions does)
I missing something? How to make it work wiftout using findViewById?