-
Notifications
You must be signed in to change notification settings - Fork 353
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Dot indicator resets to the first page after the activity is rotated #126
Comments
The issue is still unresolved, but I did a bit more digging. The current item of the However, I have fixed this issue by saving the current item as the original activity is being destroyed and restoring it in my private ViewPager2 mViewPager;
private SpringDotsIndicator mDotsIndicator;
@Override
protected void onCreate(final Bundle savedInstanceState) {
...
viewPager = findViewById(R.id.tutorial_pager);
final FragmentStateAdapter pageAdapter = new MyPageAdapter(this);
viewPager.setAdapter(pageAdapter);
if (savedInstanceState != null) {
final int position = savedInstanceState.getInt("current_position");
mViewPager.setCurrentItem(position);
}
mDotsIndicator = (SpringDotsIndicator) findViewById(R.id.spring_dots_indicator);
mDotsIndicator.setViewPager2(mViewPager);
...
}
@Override
public void onSaveInstanceState(final @NonNull Bundle bundle) {
super.onSaveInstanceState(bundle);
bundle.putInt("current_position", mViewPager.getCurrentItem());
} I can see that I'm setting the right position in the |
The issue can be reproduced easily with the provided sample. Surprisingly, it seems to happen with the |
It looks like this issue has been reported several times. The best explanation I've found is by @krodyrobi here (issue #57 ). Since issue 57 is a fairly old issue, I was wondering if there are any plans yo look into this @tommybuonomo Cheers and thanks for the nice library :) |
Hello @nachogoro 👋 |
Hello, thanks for your contribution ! |
As the title states. I set the
ViewPager2
object for theSpringDotsIndicator
in theonCreate()
method of my activity, and don't do anything else with theSpringDotsIndicator
:It behaves correctly normally. However, if I'm on e.g. my third fragment and rotate the screen, when the activity is recreated the fragment shown in the new orientation is still the third one, but the dot indicates that we are on the first fragment.
As soon as I slide the fragment slightly the dot catches up and goes to the correct position.
Is this a bug or am I missing some code in order to handle these cases?
The text was updated successfully, but these errors were encountered: