is there a way of bundling function references in Kotlin and Android so that the functions can be called from other fragments? For instance, my fragment factory method look
Maybe too late but:
Have you tried to put the val callback
inside the companion object?
Solution may be something like:
companion object {
private lateinit var callback
fun newInstance(tryAgainFunction: () -> Unit): TimeOutHandlerFragment {
val fragment = TimeOutHandlerFragment()
this.callback = tryAgainFunction
return fragment
}
}
override fun onViewCreated(view: View?, savedInstanceState: Bundle?) {
super.onViewCreated(view, savedInstanceState)
btnTryAgain.setOnClickListener { callback.invoke() }
}