简体   繁体   English

Viewpager中的片段只有在旁边的片段打开时才会刷新

[英]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: 看看之间的区别:

  • add
  • replace 更换
  • show 节目

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.

相关问题 从第二个Fragment的recyclerView中选择项目时如何切换到第一个Fragment? 两个片段都在带有 viewPager2 的 tablayout 中 - How to switch to the first fragment when selecting an item from the recyclerView of second Fragment? Both fragments are in tablayout with viewPager2 ViewPager内部片段返回父片段时不显示 - ViewPager inner fragments Not showing when returning to parent fragment 如何将数据从对话片段发送到Viewpager中的所有片段? - How to send data from a dialogue fragment to all fragments within a Viewpager? 在片段的viewpager中,如何请求将数据从一个片段拉到另一个片段 - In a viewpager of fragments, how to request to pull data from one fragment to another ViewPager在Fragment内有Fragments - ViewPager having Fragments inside Fragment Viewpager选项卡片段和正常片段 - Viewpager Tabs Fragment & Normal Fragments ViewPager片段未显示在嵌套片段中 - ViewPager fragments are not shown in nested fragment 当viewpager的最后一个片段滑动时,如何从片段变为活动? - How move from fragment to activity when viewpager's last fragment slide? 从ViewPager的片段中获取GoogleMap - Get GoogleMap from ViewPager's fragment 如何从活动的片段返回到viewpager中的片段 - How to return back to a fragment in viewpager from an Activity's fragment
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM