简体   繁体   中英

Check if a user goes back to a Fragment of a TabLayout

I have two Fragments in a TabLayout.
In one Fragment there is a method wich changes some values using the SharedPreferences.
When I change the values I always update the 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.

How I can check if a user goes back to the Fragment and updates the TextViews?

PS Sorry for my bad English

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

mViewPager.setOffscreenPageLimit(numberOfTabs);

This may help

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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