我Tools.java:標籤OnClickListener另一活動
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);}}
我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>
第一個選項卡被稱爲類「ToolDadosTubuCirc。 java「,並且此活動具有以下代碼:
package br.com.mobile4you.engtools;
import android.app.Activity;
import android.os.Bundle;
public class ToolCalcularTubuCirc extends Activity {
@Override
protected void onCreate(Bundle savedInstanceState) {
// TODO Auto-generated method stub
super.onCreate(savedInstanceState);
setContentView(R.layout.toolcalculartubucirc);
}
}
**如何在文件onClickListener「ToolDadosTubuCirc.java」中創建一個事件? 我需要創建一個函數,當人們點擊標籤「calcular」做一些測試數據時,它應該填寫「dados」標籤。
我有3個選項卡:tab1 = data; tab2 = legend; tab3 =計算。 corrent選項卡是「數據」。我需要檢查用戶何時單擊「計算」選項卡上的所有字段「數據」選項卡已完成。我不知道在其他活動(類)中爲TabDados創建onclickListener事件。我不知道tabhost和TabWidget的ID。 如何創建此事件?謝謝!**
如果我的tabhost的id是標準的android,我的id也是TabWidget。我無法做這個事件。幫我。
您是否嘗試過使用'onTabChanged(String tabId)'? – amp 2012-04-16 20:06:19