Child fragment
Add listener interface
private var dataChangeListener: DataChangeListener? = null
...
fun setDataChangeListener(dataChangeListener: DataChangeListener) {
this.dataChangeListener = dataChangeListener
}
interface DataChangeListener {
fun onDataChange()
}
Call listener when something occurs
fun updateSomeStuffs() {
...
dataChangeListener?.onDataChange()
...
}
Parent fragment
Attach listener to child fragment where it is called
class ParentFragment : BaseFragment(), Contract.View, DataChangeListener {
...
override fun onDataChange() {
// Update parent fragment here
}
...
}
Implement listener
val childFragment = ChildFragment()
childFragment.setDataChangeListener(this)
Leave a Reply