如何从TabHost移除标签 [英] How to remove tab from TabHost

查看:622
本文介绍了如何从TabHost移除标签的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在一个 TabHost 小部件,我可以创造一个新的标签,其内容(意向)使用<一个href="http://developer.android.com/reference/android/widget/TabHost.html#addTab%28android.widget.TabHost.TabSpec%29">TabHost.addTab(TabHost.TabSpec则tabspec)。

In a TabHost widget, I can create a new tab with its content (Intent) using TabHost.addTab(TabHost.TabSpec tabSpec).

我们可以通过调用<一个删除我们创建的所有选项卡href="http://developer.android.com/reference/android/widget/TabHost.html#clearAllTabs%28%29">clearAllTabs(),但我无法弄清楚如何去除标签或只是更换新的意图的选项卡里面的内容(意向)。

We can remove all tabs we created by calling clearAllTabs(), but I can't figure out how to remove the tab or just replace the content (Intent) inside the tab with new Intent.

所以我需要的东西,像 removeTab(INT指数)

so what I need something like removeTab(int index)

推荐答案

其实,clearAllTabs做的是:

Actually, clearAllTabs does that :

public void clearAllTabs() {
  mTabWidget.removeAllViews();
  initTabHost();
  mTabContent.removeAllViews();
  mTabSpecs.clear();
  requestLayout();
  invalidate();
}

和方法removeAllViews来自类的ViewGroup 。幸运的是,的ViewGroup 确实有方法去除只有一个观点:

And the method removeAllViews comes from the class ViewGroup. Luckily, ViewGroup does have methods to remove only one view :

  • removeView(查看视图)
  • removeViewAt(INT指数)
  • removeViewInLayout(查看视图)
  • removeView(View view)
  • removeViewAt(int index)
  • removeViewInLayout(View view)

知道了,我会建议继承 TabWidget TabHost 添加你需要的行为。也许还有一个更简单的方法,但是这是唯一一个我能想到的。 祝你好运

Knowing that, I would recommend to subclass TabWidget and TabHost to add the behaviour you need. Maybe there is an easier way but that's the only one I can think of. Good luck

这篇关于如何从TabHost移除标签的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆