[英]How do I add unique content to each tab in an Android app
I'm trying to make an app that has three tabs, each with different but linked content. 我正在尝试制作一个具有三个选项卡的应用程序,每个选项卡具有不同但链接的内容。 Currently, I want some features to appear on one tab but not on another. 目前,我希望某些功能显示在一个选项卡上,而不显示在另一个选项卡上。 For example, I would like a SeekBar to be displayed on only one of the tabs. 例如,我希望SeekBar仅显示在一个选项卡上。 But, currently, it is displayed for all of them. 但是,目前,所有这些都显示出来。
I greatly appreciate any help 我非常感谢您的帮助
It seems like you want to dynamically add content to the TabHost . 似乎您想将内容动态添加到TabHost 。 You will be able to add different tabs to the TabActivity once it is created based on a variable. 一旦基于变量创建TabActivity,就可以将其添加到TabActivity中。 Here is an example ... 这是一个例子...
TabHost host = findViewById(R.id.my_tabhost);
boolean boo = true; //Variable that will decide what tabs to add
host.setup(); //Need to call before adding tabs
if (boo)
host.addTab(host.newTabSpec("Hello").setIndicator("Hello").setContent(new Intent(this, HelloActivity.class)));
else
host.addTab(host.newTabSpec("Goodbye").setIndicator("Goodbye").setContent(new Intent(this, GoodbyeActivity.class));
This way the tabs will be different if boo
is true
or if boo is false. 这样,如果boo
为true
或boo为false,选项卡将有所不同。 Then you can add your content to HelloActivity
and GoodbyeActivity
. 然后,您可以将您的内容HelloActivity
和GoodbyeActivity
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.