简体   繁体   English

检查用户是否返回TabLayout的片段

[英]Check if a user goes back to a Fragment of a TabLayout

I have two Fragments in a TabLayout. 我在TabLayout中有两个片段。
In one Fragment there is a method wich changes some values using the SharedPreferences. 在一个片段中,有一种方法可以使用SharedPreferences更改某些值。
When I change the values I always update the Textviews. 更改值时,我总是更新Textviews。
This works fine. 这很好。
But when I go back into my first Fragment, I have the old values, which has been updated in the OnCreateView() method. 但是,当我回到第一个片段时,我有了旧值,该值已在OnCreateView()方法中更新。

How I can check if a user goes back to the Fragment and updates the TextViews? 如何检查用户是否返回到Fragment并更新TextViews?

PS Sorry for my bad English PS对不起,我的英语不好

您可以尝试覆盖片段的onResume方法,并在onResume内部重新读取存储在Preferences中的值,或者可以使用EventBus传播更改,或者使用RxJava重新激活更改。

mViewPager.setOffscreenPageLimit(numberOfTabs); mViewPager.setOffscreenPageLimit(numberOfTabs);

This may help 这可能会有所帮助

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM