I am trying to add a function to enable/disable some buttons in my fragment, however I am getting a compilation error
"Only safe (?.) or non-null asserted (!!.) calls are allowed on a nullable reciever"
I have tried a couple of different methods; from calling the button directly, to calling the activity where I would do the button work, but I get the same error:
private fun enableButtons(buttonState: Boolean) {
(activity as MainActivity?).enableButtons(buttonState)
// ^ error there
}
and
var button = activity.findViewById(R.id.button0) as Button
// ^ error here
button.isEnabled = false
button.isClickable = false
I'm pretty new to Kotlin and can't work out how can I access the buttons without passing in a view