开发者

How to close one single tab in android tablayout without clearing all the tabs and adding again

开发者 https://www.devze.com 2023-04-01 19:40 出处:网络
There is a method to add a tab in TabHost as well as clear all tabs, but there are no APIs to remove one single tab.

There is a method to add a tab in TabHost as well as clear all tabs, but there are no APIs to remove one single tab.

F开发者_如何学Pythonollowing the logic in clearAllTabs tried to

tabwidget.removeViewAt(index);
tabHost.getTabContentView().removeViewAt(index)

After this the behaviour is strange. I assume that is because the mTabSpecs still contain the tabspec reference. mTabSpecs is a private variable in TabHost and there are not get methods to get a handle to this.

How to resolve the issue if one wants to close a single tab, and yes I have tried to clear all the tabs and add back all the tabspecs. It does not work for my usecase where some views contains some information regarding a session. If I recreate those tabspecs, I will go back to the starting point in those views.


You can try to set Visibility of the Tab that you want to close to View.GONE.


resolved with the View.GONE but with method which specifically checks for the visibility before counting the tabs. drawback is the index of the view cannot be changed.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号