I have a ViewPager which contains several TextViews inside its fragment which they have different font sizes.
In addition, I got buttons for increase/decreasing font size which calculate font size of each textView by adding its default size plus a value called STEP (which changes by inc/dec font size button).
My problem is if a view is displayed for first time after applying size changes, It will create textViews in desired size during onCreateView() however if fragment was cached already and onCreateView is not called again, I don't know how to update their textViews considering only one of cached fragments is displaying on screen (and i can update it with no problem) but others are not displayed (I don't know if they are attached to activity or not in this case).
In other words how can i detect which fragments are cached by ViewPager and their onCreateView already called (these are fragments which update to their views must be applied). I marked them in light green with question marks in below picture:
相关问题
- How can I create this custom Bottom Navigation on
- Bottom Navigation View gets Shrink Down
- How to make that the snackbar action button be sho
- Listening to outgoing sms not working android
- How to create Circular view on android wear?
相关文章
- android开发 怎么把图片放入drawable的文件夹下
- android上如何获取/storage/emulated/下的文件列表
- androidStudio有个箭头不认识
- SQLite不能创建表
- Windows - Android SDK manager not listing any plat
- Animate Recycler View grid when number of columns
- Why is the app closing suddenly without showing an
- Android OverlayItem.setMarker(): Change the marker
In order to have a list of cached items by ViewPager I changed my Custom Adapter which an extension FragmentStatePagerAdapter:
HashMap<Integer, FragmentDipsplayPageContent> cachedFragmentHashMap
to my adapterUpdate getItem() method like this
Update destroyItem() method of adapter like this
Add a getter to access HashMap of cached Fragments from activity:
update using this collection inside activity:
This way all cached fragments including visible and off-screen fragments are updated.
Accepted answer is nice but you shouldn't cache all the items. Instead, you can use this method:
For example, there are many many items with image and animations. If you cache all of them, this probably will result with an
OutOfMemoryError
. To prevent, you can define page limit to be cached.Edit: Instead
HashMap<Integer, Object>
, it is better to useSparseArray<Object>
.Use
FragmentStatePagerAdapter
instead ofFragmentPagerAdapter
for yourViewPager
Adapter