【发布时间】:2011-06-21 09:29:23
【问题描述】:
我创建了一个带有 tabhost 等的 android 项目。 我可以切换到我想要的视图,一切都很好。
现在,我想使用一个按钮来启动另一个选项卡...
这是我的 main.class :
public class Main extends TabActivity{
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
Log.v("", "Welcome in Main");
setContentView(R.layout.tab);
TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); // Le TabHost a des Tabs
TabSpec firstTabSpec = tabHost.newTabSpec("tid1"); // TabSpec: new tab - TabSpec : setContent to the tab
firstTabSpec.setIndicator("Informations", getResources().getDrawable(R.drawable.database)).setContent(new Intent(this,FirstTab.class));
tabHost.addTab(firstTabSpec);
TabSpec secondTabSpec = tabHost.newTabSpec("tid1");
secondTabSpec.setIndicator("Graphiques", getResources().getDrawable(R.drawable.chart)).setContent(new Intent(this,SecondTab.class));
tabHost.addTab(secondTabSpec);
TabSpec thirdTabSpec = tabHost.newTabSpec("tid1"); // tid1 is firstTabSpec Id (used to access outside)
thirdTabSpec.setIndicator("Réglages", getResources().getDrawable(R.drawable.settings)).setContent(new Intent(this,ThirdTab.class));
tabHost.addTab(thirdTabSpec);
我试过了:
public void secondJour(View v) {
Log.v("", "onCLick 001");
new Intent(this,SecondTab.class);
}
但它似乎没有运行(没有错误,但屏幕上没有新内容..)
你有解决办法吗?
感谢阅读!!!
【问题讨论】:
-
你可以为按钮编写整个onClick方法吗?谢谢...
-
@Jim:谢谢并完成 ;-) 但没什么特别的!如果你想看看我是如何制作主要方法(管理标签的),问我;-)
标签: android android-layout android-intent android-tabhost