Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

TabLayout crashing after updating support library to 23.2.0

I am using TabLayout from the design library with the ViewPager, linking them using the function setupWithViewPager. The app is crashing in scenarios where it recreates the tabs, after the tab contents have been changed. Crash 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)

The crash is occuring after updating to support library 23.2.0, doesn't reproduce till v23.1.1.

like image 202
Mihir Shah Avatar asked Feb 28 '16 18:02

Mihir Shah


People also ask

What is TabLayout?

TabLayout is used to implement horizontal tabs. TabLayout is released by Android after the deprecation of ActionBar. TabListener (API level 21). TabLayout is introduced in design support library to implement tabs. Tabs are created using newTab() method of TabLayout class.

How we can add tabs at runtime in TabLayout?

You create tabs via newTab() . From there you can change the tab's label or icon via TabLayout. Tab. setText(int) and TabLayout.

How do I add an icon to TabLayout?

TabLayout is introduced in the design support library to implement tabs. Tabs are created using the newTab() method of TabLayout class. The title and icon of Tabs are set through setText(int) and setIcon(int) methods of TabListener interface respectively.


2 Answers

Just found that this is an internal bug in Support library v23.2.0, registered at : https://code.google.com/p/android/issues/detail?id=201827

like image 70
Mihir Shah Avatar answered Sep 21 '22 03:09

Mihir Shah


This was bug reported on google https://code.google.com/p/android/issues/detail?id=201827

But after release of Android Support Library, revision 23.2.1 (March 2016) This is fixed now.

just update Support Library to Android Support Library to 23.2.1

like image 29
Amit Vaghela Avatar answered Sep 23 '22 03:09

Amit Vaghela