tabhost/tabspec 是否有类似 onclick/onfocus 的东西?
我有一个完全工作的 tabhost/tabspec 应用程序(第一个工作的自制应用程序:D)请参阅下面的代码。 现在,如下:当按下选项卡 NORM 时,我想运行几行代码。 tabhost/tabspec 是否有类似 onclick 的东西?任何帮助表示赞赏
public class AndroidTabLayoutActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
// Tab for Dag
TabSpec dagspec = tabHost.newTabSpec("Dag");
dagspec.setIndicator("DagRooster", getResources().getDrawable(R.drawable.icon_dag_tab));
Intent dagIntent = new Intent(this, DagActivity.class);
dagspec.setContent(dagIntent);
// Tab for Norm
TabSpec normspec = tabHost.newTabSpec("Norm");
// setting Title and Icon for the Tab
normspec.setIndicator("Normaal", getResources().getDrawable(R.drawable.icon_norm_tab));
Intent normIntent = new Intent(this, NormActivity.class);
normspec.setContent(normIntent);
// Tab for Instel
TabSpec instelspec = tabHost.newTabSpec("Instel");
instelspec.setIndicator("Info", getResources().getDrawable(R.drawable.icon_setting_tab));
Intent instelIntent = new Intent(this, InstelActivity.class);
instelspec.setContent(instelIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(dagspec); // Adding photos tab
tabHost.addTab(normspec); // Adding songs tab
tabHost.addTab(instelspec); // Adding videos tab
tabHost.setCurrentTab(2);
}
}
I've a fully working tabhost/tabspec app (first working self-made app ever :D) see code beneath.
Now, the following: when tab NORM is pressed I want to run a few lines of code. Is there something like an onclick for the tabhost/tabspec. Any help appreciated
public class AndroidTabLayoutActivity extends TabActivity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);
TabHost tabHost = getTabHost();
// Tab for Dag
TabSpec dagspec = tabHost.newTabSpec("Dag");
dagspec.setIndicator("DagRooster", getResources().getDrawable(R.drawable.icon_dag_tab));
Intent dagIntent = new Intent(this, DagActivity.class);
dagspec.setContent(dagIntent);
// Tab for Norm
TabSpec normspec = tabHost.newTabSpec("Norm");
// setting Title and Icon for the Tab
normspec.setIndicator("Normaal", getResources().getDrawable(R.drawable.icon_norm_tab));
Intent normIntent = new Intent(this, NormActivity.class);
normspec.setContent(normIntent);
// Tab for Instel
TabSpec instelspec = tabHost.newTabSpec("Instel");
instelspec.setIndicator("Info", getResources().getDrawable(R.drawable.icon_setting_tab));
Intent instelIntent = new Intent(this, InstelActivity.class);
instelspec.setContent(instelIntent);
// Adding all TabSpec to TabHost
tabHost.addTab(dagspec); // Adding photos tab
tabHost.addTab(normspec); // Adding songs tab
tabHost.addTab(instelspec); // Adding videos tab
tabHost.setCurrentTab(2);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您只需将 TabHost 添加到 OnTabChangeListener() 中,如下所示:
You just need to add TabHost to OnTabChangeListener() like this:
我想您可以使用
或者
您可以使用此SO讨论中讨论的方法。
I guess you can use
or
You may use the approach discussed in this SO discussion.