How to replace a Fragment on button click of that fragment?

后端 未结 6 1057
南笙
南笙 2020-11-30 09:00

I have an activity containing multiple fragments. Activity initially have fragment and in it have two buttons. Upon clicking this button I have to replace the fragment by ne

6条回答
  •  北荒
    北荒 (楼主)
    2020-11-30 09:50

    From the future 2017 and after, there exists different libraries that triggers Events using Bus and now you can use it to tell the activity when an event is trigger in a fragment that it owns.

    Refer to:

    RxBus with RxJava

    You can check new architectures suggested by Google

    ViewModel

    Don't use the approach in the accepted answer, get really ugly with more than 3 different events from fragments

提交回复
热议问题