question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

position not retained when coming back from another fragment

See original GitHub issue

Hi, I use navigation graph in my app and when I leave fragment which contains viewpager and come back (click on “skip” button in attached gif), viewpager’s position is retained, but dots indicator is reset. I know that view is recreated when leaving and coming back, but I noticed ViewPager2.OnPageChangeCallback’s onPageSelected is called with last position, but dots indicator somehow doesn’t react. But when I scroll , indicator jumps to correct position. Please have a look at attached video. Thanks ezgif-1-d6bbe5d48bf5

this is how it’s initialised in onActivityCreated() method:

        val pagerAdapter = MyViewPagerAdapter(activity!!)
        viewPager.adapter = pagerAdapter
        pagerIndicator.setViewPager2(viewPager)

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:2
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

8reactions
VladPalamarchukcommented, Dec 3, 2019

@palicka I had the same issue, look my solution, hope it will helps

indicator.setViewPager(pager) pager.post { adapter.notifyDataSetChanged() }

Where indicator - is indicator view, pager - is ViewPager, adapter - is PagerAdapter. Indicator internally react on adapter changes, so it will redraw indicators correctly. Hope it helps 😃

0reactions
tommybuonomocommented, Apr 30, 2022

Hello, thanks for your contribution ! This issue is now fixed in the new version 4.3 Thanks 🔥

Read more comments on GitHub >

github_iconTop Results From Across the Web

Listview position is incorrectly retain after coming back to ...
when i click on list item a another fragment will load with backstack .Before loading the new fragment i save details about list-view...
Read more >
Fragment manager - Android Developers
In other words, the transaction is reversed. If there are no more fragment transactions on the stack, and if you aren't using child...
Read more >
how to keep recyclerview scrolled position when i back from ...
Hello, i have gridview when i press item new fragment starts but when i come back the grid is not resumes from the...
Read more >
Saving Fragment State Yourself - Medium
Any Fragments that are still in the FragmentManager (either directly visible or still on the back stack) will have their state saved when...
Read more >
ViewPager with FragmentPagerAdapter - CodePath Cliffnotes
Usage · Layout ViewPager · Define Fragments · Setup FragmentPagerAdapter · Apply the Adapter · Selecting or Getting the Page · Setup OnPageChangeListener....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found