Solution to not displaying text after tablayout is associated with viewpager

When you use the addtab () method to dynamically add text to tablayout, the problem of not displaying the title text may occur. The real situation is not that the text is not displayed, but that the viewpager adds many empty titles to the tablayout, resulting in the title manually added before being crowded behind. I don't believe you can turn back more and come out. How do these empty titles come into being? By analyzing the tablayout source code, we can quickly find out this problem. The code of one method is as follows:

Let's look at this line:

Suddenly, you can see that the pageadapter method is called in the tablayout to add the title, and the number of titles is set in the getcount() method of the pageadapter, and the text of the title is set in the getpagetitle() method of the pageadapter. At this point, the solution comes out: instead of manually using the addtab method to add a title for the viewpager, create a list and set it in the getpagetitle method of the pageadapter. The code is as follows:

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>