What is the difference between TabLayout.TabView and TabLayout.Tab

Eitanos30 :

I'm trying to understand the difference between both classes that are both inner class of TabLayout class. In the following link : example

I see that method onTabSelectedd(TabLayout.Tab tab) in the example, gets a reference to Tab object, and for a reason that i can't understand, it is written there:

 ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
 ViewGroup vgTab = (ViewGroup) vg.getChildAt(tab.getPosition());

is Tab object enough? the way i see the things the second line should return the same object as Tab that it a parameter of the above method. When i'm printing toString() for both objects i see that the parameter tab is instance of TabView and vgTab is instance of Tab Can someone explain me my misunderstanding?

Ben P. :

TabLayout.Tab is not a subclass of View. It is a "conceptual" tab, an object that holds all the information necessary to render a single tab in a TabLayout (text, icon, etc).

TabLayout.TabView is a subclass of View. It knows how to take a Tab and render its text, its icon, etc.

In your linked question and answer, the reason for code like this:

ViewGroup vg = (ViewGroup) tabLayout.getChildAt(0);
ViewGroup vgTab = (ViewGroup) vg.getChildAt(tab.getPosition());

is that the onTabSelected() method only receives an argument of type Tab, but needs to do view-related things (change text size), so it must take that Tab and "find" the corresponding TabView that goes with it.

The code is assuming that the first child of the tabLayout is going to be a container of tab views, and then within that container it looks for the view at the same position as the parameter tab. Then it scans all children of that view, and changes the text size of any TextView it finds.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=220117&siteId=1