TabLayout crashes after updating support library to 23.2.0

I am using TabLayout from the design library using ViewPager , linking them using the setupWithViewPager function. The application crashes in the scenarios where it recreates the tabs after the contents of the tab have been changed. Failure Trace:

 java.lang.IllegalArgumentException: Tab belongs to a different TabLayout. at android.support.design.widget.TabLayout.addTab(TabLayout.java:433) at android.support.design.widget.TabLayout.populateFromPagerAdapter(TabLayout.java:772) at android.support.design.widget.TabLayout.setPagerAdapter(TabLayout.java:763) at android.support.design.widget.TabLayout.setupWithViewPager(TabLayout.java:715) 

Crash after upgrade to support library 23.2.0, does not play until v23.1.1.

+5
source share
4 answers

It just turned out that this is an internal error in the support library v23.2.0, registered at: https://code.google.com/p/android/issues/detail?id=201827

+7
source

It was a bug reported by google https://code.google.com/p/android/issues/detail?id=201827

But after the release of the Android support library version 23.2.1 (March 2016) Now this is fixed.

just upgrade your support library to Android Support Library to 23.2.1

+2
source

I have the same problem, and I found that the new Tablayout uses a pool to cache Tab. in 23.1.1 public Tab newTab() { return new Tab(this); } public Tab newTab() { return new Tab(this); } and in 23.2.0 public Tab newTab() { Tab tab = sTabPool.acquire(); if (tab == null) { tab = new Tab(this); } tab.mView = createTabView(tab); return tab; } public Tab newTab() { Tab tab = sTabPool.acquire(); if (tab == null) { tab = new Tab(this); } tab.mView = createTabView(tab); return tab; }

therefore, if you use newTab () to create a tab, and for some reason you did not add it to TableLayout. The next time you enter another action using TabLayout, this will happen.

+1
source

I still see this problem in the lib support version: 25.3.1. Therefore, to avoid failure, I deleted AllTabs () and again created a new instance for the tab and added it to Tablayout.

  gauge_tab.removeAllTabs() gauge_tab.addTab(gauge_tab.newTab().setText(R.string.flash_gauge_04)) gauge_tab.addTab(gauge_tab.newTab().setText(R.string.flash_gauge_06)) gauge_tab.addTab(gauge_tab.newTab().setText(R.string.flash_gauge_08)) 
0
source

Source: https://habr.com/ru/post/1244059/


All Articles