Frage

Just to clarify. I have a TabHost, and inside that tabhost are like 5 tabs. I'm playing around with tabhost so I'm trying to close one of the tabs (i.e. one of the child views). The problem is that even though it works, the layout below the tabs stays the same, i.e. if I had a textview in the tab I'm closing, and a button in the main tab, when I close the tab with the textview, the tab does disappear but the textview remains. This is the code I'm using to close a tab:

    int vPos = mHost.getCurrentTab();
    TabWidget tWidget = mHost.getTabWidget();

    if (vPos != 0) {
        tWidget.setCurrentTab(0);
        tWidget.removeView(mHost.getTabWidget().getChildAt(vPos));

    }

So basically it closes the tab, switches to the other tab, but the layout BELOW the tabs remains the exact same. I know people would like me to post the full code including layout and whatnot, but this is a general thing, it doesn't regard the layout, it only regards the tabs (if I'm mistaken feel free to point it out).

Maybe I'm supposed to call invalidate() on the views but that doesn't work whether I invalidate the child view, the tab widget or the tabhost.

War es hilfreich?

Lösung

Unfortunately this is an issue internally in TabWidget due to lack of a removeTab function. When you call removeView from the TabWidget, the removeView is called from the ViewGroup class which has no notion of tabs. As a result, you are actually only removing the actual tab and leaving the indexes and layouts below unaffected.

A excessive workaround would be to call removeAllViews and re-add all the views.

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top