Reputation: 11
In one of my app, I am using tab layout and viewpager with three fragments. In each fragment I am fetching data from server using Java Rest API. This server data depend upon fragment button click. E.g.
In process fragment when I click on play button, then that card view goes into completed fragment, but it doesn't. when I refresh activity that time it goes, mean when activity close and then start. what should I do to refresh fragment?
Upvotes: 1
Views: 24417
Reputation: 174
Try this in your Fragment class
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
// Refresh your fragment here
}
}
Upvotes: 1
Reputation: 2119
Whatever operation you want to perform for refreshing fragment just put it inside one method and call it from onStart()
method inside your fragment, worked for me.
Upvotes: 0
Reputation: 796
You can try to refresh fragment like this:
FragmentTransaction ft = getFragmentManager().beginTransaction();
ft.detach(YourFragment.this).attach(YourFragment.this).commit();
Upvotes: 9
Reputation: 320
I think, that you need to update Adapter on model changes, but not whole Fragment.
Upvotes: 0
Reputation: 982
Try this one ! Paste this code in your Activity.
viewpager.setOffscreenPageLimit(1);
Upvotes: -1