[英]Fragment in Viewpager only refreshing when it's open from fragments next to it
So basically i have 4 fragments I'm currently working on second. 所以基本上我有4个片段,我目前正在做第二个。 I have some weird situation here.
我有一些奇怪的情况。 When app started it open fragment on position 1 then if I navigate to fragment 2 via tabs on top fragment 2 will update, then if I open fragment 3 from fragment 2 and return to fragment 2 from fragment 3 it will also update.
当应用程序启动时,它会在位置1上打开片段然后如果我通过顶部片段2上的选项卡导航到片段2将更新,那么如果我从片段2打开片段3并从片段3返回片段2它也将更新。 But if I choose to open fragment 4 and then return to fragment 2 it won't refresh.
但是,如果我选择打开片段4然后返回到片段2,它将不会刷新。 This is method that I'm calling to refresh fragment
这是我正在调用刷新片段的方法
@Override
public void setUserVisibleHint(boolean isVisibleToUser) {
super.setUserVisibleHint(isVisibleToUser);
if (isVisibleToUser) {
loadEvents();
}
Log.d("TAG", "VISIBLE");
}
in LoadEvents there are few recyclerview setting their adapters. 在LoadEvents中,很少有recyclerview设置其适配器。 Nothing speciall
没什么特别的
I think it is because when you call fragment 3 and when you return to the fragment 2 you use .replace
, instead when you go to the fragment 4 you use .add
and to return to the fragment 2 .show
. 我认为这是因为当你调用片段3时,当你返回到片段2时,你使用
.replace
,而当你转到片段4时,你使用.add
并返回到片段2 .show
。
looks at the differences between: 看看之间的区别:
https://developer.android.com/reference/android/app/FragmentTransaction.html https://developer.android.com/reference/android/app/FragmentTransaction.html
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.