也可以在Fragment的onAttach(contex:Context)中设置监听:
override fun onAttach(context: Context?) {
super.onAttach(context)
if (context is OnTitleClickListener) {
listener = context
} else {
throw RuntimeException(context.toString() + " must implement OnTitleClickListener")
}
}
override fun onAttach(context: Context?) {
super.onAttach(context)
if (context is OnTitleClickListener) {
listener = context
} else {
throw RuntimeException(context.toString() + " must implement OnTitleClickListener")
}
}
2019-04-21