Issue
I would like to refresh fragment(SentAtt) from ViewPager. I use TabLayout to detect selected fragment but i don't know how can i refresh specific fragment when tab is selected.
tabLayout!!.addOnTabSelectedListener(object : TabLayout.OnTabSelectedListener {
override fun onTabSelected(tab: TabLayout.Tab) {
viewPager.currentItem = tab.position
if(tab.position==1){
val sentAtt:SentAtt
}
}
override fun onTabUnselected(tab: TabLayout.Tab) {
}
override fun onTabReselected(tab: TabLayout.Tab) {
}
})
Solution
To correctly encapsulate your Fragment you should not try to refresh it from outside the Fragment.
Viewpager2 and Viewpager with BEHAVIOR_RESUME_ONLY_CURRENT_FRAGMENT flag set then a Fragment will only be moved to the RESUMED state when it is selected, thus you should put you refresh code in the Fragments onResume
method.
As the refresh code is inside the Fragment you don't work out which fragment to refresh.
Answered By - Andrew
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.