Communication from Activity to Fragment with ViewPager

情到浓时终转凉″ 提交于 2019-12-04 10:50:01
kris larson

You need to set up some event listener logic where the fragment registers with the activity for the event it wants. The fragment should register on creation and unregister on destruction.

Then when the event occurs, the activity goes through the list of registered listeners and notifies them of the event.

I give a detailed example in this answer.

You can use an event bus library to simplify some of the wiring between the activity and the fragments.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!