【发布时间】:2013-08-02 04:36:21
【问题描述】:
我想查看选择了哪个选项卡并根据该选择执行特定代码。我使用以下教程创建带有图像的列表,问题是列表项位于单独的选项卡中,我遵循的代码仅设置第一个选项卡的图像。
http://www.debugrelease.com/2013/06/24/android-listview-tutorial-with-images-and-text/
这是我设置标签的方式。
TabHost tabHost = getTabHost();
//Tab for Students
TabSpec studentSpec = tabHost.newTabSpec("Students");
//set the tile and icon
studentSpec.setIndicator("Students", getResources().getDrawable(R.drawable.icon_students));
Intent songsIntent = new Intent(this, StudentsTab.class);
studentSpec.setContent(songsIntent);
//Tab for Support
TabSpec supportSpec = tabHost.newTabSpec("Support");
//set the tile and icon
supportSpec.setIndicator("Support", getResources().getDrawable(R.drawable.icon_support));
Intent videosIntent = new Intent(this, SupportTab.class);
supportSpec.setContent(videosIntent);
//tabHost.addTab(homeSpec);
tabHost.addTab(studentSpec);
tabHost.addTab(supportSpec);
}
所以我在教程中的 Model.java 类中有两个方法,每个方法运行适当的图标和文本。我需要在特定选项卡上调用这些。
谢谢!
【问题讨论】:
-
tabhost 现在在 android 中已被弃用。所以我建议不要使用它。