我的表主机tools.java:
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.tabtools);
Resources res = getResources();
TabHost tabHost = getTabHost();
TabHost.TabSpec spec;
Intent intent;
// TabDados
intent = new Intent().setClass(this, ToolDadosTubuCirc.class);
spec = tabHost.newTabSpec("dados")
.setIndicator("Dados", res.getDrawable(R.drawable.icondados))
.setContent(intent);
tabHost.addTab(spec);
// TabLegenda
intent = new Intent().setClass(this, ToolLegendaTubuCirc.class);
spec = tabHost
.newTabSpec("legenda")
.setIndicator("Legenda",
res.getDrawable(R.drawable.iconlegenda))
.setContent(intent);
tabHost.addTab(spec);
// TabCalcular
intent = new Intent().setClass(this, ToolCalcularTubuCirc.class);
spec = tabHost
.newTabSpec("calcular")
.setIndicator("Calcular",
res.getDrawable(R.drawable.iconcalcular))
.setContent(intent);
tabHost.addTab(spec);
// TabCorrente
tabHost.setCurrentTab(0);
}}每一种意图都是一种活动。在每个“file.java”命令中,必须执行计算。
在"dados.java“中,我获取用户的信息。当他们点击“计算器”选项卡时,必须验证所有数据是否已经完成。
我想我需要一个"onclicklistener“为每个标签,就像一个按钮,对吗??
怎么做的?当单击选项卡“Dados”选项卡“Legenda”选项卡“计算器”时如何创建运行代码的事件?
注意:我需要检查从文件“ToolDadosCircular.java”中单击了哪个选项卡。
编辑: tabtools.xml代码:
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@android:id/tabhost"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:layout_above="@+layout/rowLog"
android:layout_below="@+layout/rowLine" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical"
android:padding="5dp" >
<TabWidget
android:id="@android:id/tabs"
android:layout_width="fill_parent"
android:layout_height="wrap_content" />
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:padding="5dp" />
</LinearLayout>
</TabHost>发布于 2012-04-16 14:19:55
试一试
tabHost.getChildAt(yourtab).setOnClickListener(new View.onClickListener()
{
@Override public void onClick(View view){
//your code
}
}编辑:我猜你的课是这样的
public class ToolDadosTubuCirc extends Activity{
@Override public void onCreate(Bundle bundle){
//code...
TabHost tabHost = (TabHost) getParent().findViewById(yourTabHostId);
//do what you want with tabHost
//code...
}
}https://stackoverflow.com/questions/10175841
复制相似问题