I would like to reload (re-create layout) fragment (including call onCreateView()) when the user does action pull to refresh from the activity. Because when the fragment has created, onCreateView() can not be called again, except the case the activity be recreated. How can I do that?
Asked
Active
Viewed 766 times
0
-
Note that you only need to reload data in a ViewPager Fragment if it's the one currently shown to the user. In your case, you can just call into the current ViewPager Fragment when the user performs the "pull to refresh" action. – Daniel Nugent Aug 30 '17 at 17:22
-
@DanielNugent : No, I want my fragment can re-created, so I wrote (including call onCreateView()) . Because I want to inflate my other layout when data on server has changed. This's same AB testing – Huy Nguyen Aug 30 '17 at 17:26
-
@DanielNugent: Can you mark my question is not duplicated? I need the answers – Huy Nguyen Aug 30 '17 at 17:35
-
Since the ViewPager controls instantiation of each Fragment, it looks like the way you're trying to solve your problem might not be possible. However, there are alternative solutions that will work, take a look here: https://stackoverflow.com/questions/12222925/set-new-layout-in-fragment – Daniel Nugent Aug 30 '17 at 18:33
1 Answers
1
Nest ListView inside Swipe to Refresh and implement SwipeRefreshLayout in Activity or fragment
`<android.support.v4.widget.SwipeRefreshLayout android:layout_width="match_parent"
android:layout_height="match_parent"
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_marginTop="?attr/actionBarSize"
>`
Than when swipetorefresh is hit attach and detach Fragment
// Reload current fragment
Fragment frg = null;
frg = getSupportFragmentManager().findFragmentByTag("Your_Fragment_TAG");
final FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
ft.detach(frg);
ft.attach(frg);
ft.commit();

skryshtafovych
- 572
- 4
- 16
-
This does not help to resolve my problem. please read my question again, thanks – Huy Nguyen Aug 30 '17 at 20:17