astuetz / PagerSlidingTabStrip

An interactive indicator to navigate between the different pages of a ViewPager
139 stars 44 forks source link

Crash when the FragmentPagerAdapter's data changes #66

Open adipascu opened 10 years ago

adipascu commented 10 years ago

I created a repo that has a simple project to reproduce the bug https://github.com/adi1133/PageSlidingTabStripBug

Click the Add Fragment button and go past the last fragment, the app will crash.

adipascu commented 10 years ago

I made a branch that shows how I fixed the problem in my project https://github.com/adi1133/PageSlidingTabStripBug/tree/bug_fixed

PagerSlidingTabStrip::notifyDataSetChanged is not called when the adapter of the PageView changes content, so I call it manually when needed

austynmahoney commented 10 years ago

I am seeing this same issue, and this fix resolved part of it for me. An NPE still occurs if a tab you are on is removed. The tabs are out of sync with the adapter at that time, so the call to onPageScrolled throws an NPE because tabsContainer has no child views.

scrollToChild(position, (int) (positionOffset * tabsContainer.getChildAt(position).getWidth()));

The PagerSlidingTabStrip already has a reference to the ViewPager. I'll look to see if it can hook into its notifyDataSetChanged when it is set using setViewPager(...).

mariobuc commented 6 years ago

how can I update the contents of the tab strip at run time. notifyDataSetChanged does not work. MyPagerAdapter never rerun getItem