how to send data from one fragment to another fragment in android?

前端 未结 3 496
一生所求
一生所求 2020-12-12 04:40

Hello I make a simple tab view using pager and fragment . So I have two tabs in my view .In one tab I have list view in which each row have textview and favourite

3条回答
  •  没有蜡笔的小新
    2020-12-12 04:50

    There are few ways to do it.

    The most basic and recommended one is define an interface in your sending Fragment, then make the container Activity implement that interface, so you can send data from your Fragment to the Activity. From that you can send data to your receiving Fragment.
    Take a look at this official tutorial from Google:
    http://developer.android.com/training/basics/fragments/communicating.html

    Another way is using Bus event style, it's much cooler than the previous one. You can do so with Otto. Subscribe in your receiving Fragment, then just send any data you want from your sending Fragment, no need to communicate or write lengthy interfaces.

提交回复
热议问题