控制选项卡小部件中的 XML (Android)
我使用以下代码来设置 TabWidget:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("tab_1").setIndicator("Tab1", getResources().getDrawable(R.drawable.tab_1)).setContent(new Intent(this, TabClass1.class)));
mTabHost.addTab(mTabHost.newTabSpec("tab_2").setIndicator("Tab2", getResources().getDrawable(R.drawable.tab_2)).setContent(new Intent(this, TabClass2.class)));
mTabHost.addTab(mTabHost.newTabSpec("tab_3").setIndicator("Tab3", getResources().getDrawable(R.drawable.tab_3)).setContent(new Intent(this, TabClass3.class)));
mTabHost.setCurrentTab(0);
}
因此,TabClass1、TabClass2 和 TabClass3 是包含在我的包中的单独的 .java 文件。我能够在每个 .java 文件中创建内容,并在选择每个选项卡时显示内容 - 但如何为每个 .java 文件分配 XML 布局文件?
我尝试了各种设置,但无法在 XML 布局中创建 TextView 并在选择特定选项卡时显示它。
I am using the following code to setup a TabWidget:
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost mTabHost = getTabHost();
mTabHost.addTab(mTabHost.newTabSpec("tab_1").setIndicator("Tab1", getResources().getDrawable(R.drawable.tab_1)).setContent(new Intent(this, TabClass1.class)));
mTabHost.addTab(mTabHost.newTabSpec("tab_2").setIndicator("Tab2", getResources().getDrawable(R.drawable.tab_2)).setContent(new Intent(this, TabClass2.class)));
mTabHost.addTab(mTabHost.newTabSpec("tab_3").setIndicator("Tab3", getResources().getDrawable(R.drawable.tab_3)).setContent(new Intent(this, TabClass3.class)));
mTabHost.setCurrentTab(0);
}
So, TabClass1, TabClass2 and TabClass3 are separate .java files that are contained within my package. I am able to create content within each of these .java files and display the content when each tab is selected - but how do I assign an XML layout file to each of the .java files?
I have tried various setups but have been unable to create a TextView in an XML Layout and have it display when a particular tab is selected.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
好的,在你的 TabClass1.class 中,你必须有类似
布局的内容 myContentA.xml 必须类似于...
你将在 TabClass2.class 和 TabClass3.class 中重用此 xml 布局,或者创建 myContentB.xml 和 myContentC.xml
ok in your TabClass1.class you must have somethin like
your Layout myContentA.xml must be similar to...
you will reuse this xml layout in TabClass2.class and TabClass3.class or create myContentB.xml and myContentC.xml