Pep
Pep

Reputation: 11

How do I dynamically update a fragment in a FragmentPagerAdapter

I'm writing a simple Fragment Activity with a FragmentPagerAdapter and two Fragments, where I need to show certain data in tab2 related to my selection in tab1. But the data in tab2 is never updated. Is there any common procedure for this?

Upvotes: 1

Views: 77

Answers (2)

Pep
Pep

Reputation: 11

Solved. I just created one instance of each Tab and added an update() method on tab 2 which I called from Tab 1. I couldn't find a built in solution so I did it my way.

Upvotes: 0

s.d
s.d

Reputation: 29436

You'll need a common holder for data, Activity object is most suitable, since it is parent of both fragments. All fragments can use getActivity() in onCreate(). You can call a method of Activity object to get selected data. The other fragment can similarly, call a method of Activity object to set selected data.

Upvotes: 1

Related Questions