我想从TabHost
:
public class OngletParcelleListeBatiments extends Activity {
private TabHost mTabHost;
private String bien_code;
public OngletParcelleListeBatiments() {
super();
}
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.onglet_parcelle_batiment);
mTabHost = (TabHost)findViewById(R.id.onglets);
mTabHost.setup();
Bundle dataSent = getIntent().getExtras();
bien_code = dataSent.getString("bien_code");
// first tab
TabHost.TabSpec parcelle = mTabHost.newTabSpec("parcelle");
View onglet = getLayoutInflater().inflate(R.layout.template_tab_onglets, null);
TextView label = (TextView) onglet.findViewById(R.id.tabLabel);
label.setText(getResources().getString(R.string.parcelle));
parcelle.setIndicator(onglet);
parcelle.setContent(R.id.tabContentParcelle); // I want to send data to the activity of this layout
mTabHost.addTab(parcelle);
TabHost.TabSpec batiment = mTabHost.newTabSpec("batiments");
View onglet = getLayoutInflater().inflate(R.layout.template_tab_onglets, null);
TextView label = (TextView) onglet.findViewById(R.id.tabLabel);
label.setText(getResources().getString(R.string.titre_liste_batiments));
batiment.setIndicator(onglet);
batiment.setContent(R.id.tabContentBatiments); // I want to send data to the activity of this layout
mTabHost.addTab(batiment);
mTabHost.setCurrentTab(0);
}
}
TabHost
onglet_parcelle_batiment.xml的布局:
<?xml version="1.0" encoding="utf-8"?>
<TabHost
xmlns:android="http://schemas.android.com/apk/res/android"
android:id="@+id/onglets"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<LinearLayout
android:orientation="vertical"
android:layout_width="match_parent"
android:layout_height="match_parent"
>
<TabWidget
android:id="@android:id/tabs"
android:orientation="horizontal"
android:layout_width="match_parent"
android:layout_height="wrap_content"
/>
<FrameLayout
android:id="@android:id/tabcontent"
android:layout_width="match_parent"
android:layout_height="match_parent">
<include
android:id="@+id/tabContentParcelle"
layout="@layout/parcelle"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
<include
android:id="@+id/tabContentBatiments"
layout="@layout/liste_batiments"
android:layout_width="match_parent"
android:layout_height="wrap_content" />
</FrameLayout>
</LinearLayout>
</TabHost>
包含的layout
id = tabContentParcelle:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:paddingTop="@dimen/marginLeftFieldset"
style="@style/ImpotsStyle"
android:orientation="vertical">
<ScrollView
android:layout_width="fill_parent"
android:layout_height="fill_parent" >
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="@dimen/marginLeftFieldset"
android:layout_marginRight="@dimen/marginRightFieldset"
android:layout_marginBottom="@dimen/margingBottomFieldset"
android:paddingTop="@dimen/paddingTopFieldset"
android:background="@drawable/fieldset">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/identification"
style="@style/ImpotsStyleLabel"
/>
<EditText
android:id="@+id/identification"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLength="25"
android:layout_marginRight="@dimen/marginRightScreen"
>
<requestFocus />
</EditText>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/denomination"
style="@style/ImpotsStyleLabel"
/>
<EditText
android:id="@+id/denomination"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLength="25"
android:layout_marginRight="@dimen/marginRightScreen"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="@dimen/marginLeftFieldset"
android:layout_marginRight="@dimen/marginRightFieldset"
android:layout_marginBottom="@dimen/margingBottomFieldset"
android:paddingTop="@dimen/paddingTopFieldset"
android:background="@drawable/fieldset">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/datePremConstr"
style="@style/ImpotsStyleLabel"
/>
<EditText
android:id="@+id/datePremConstr"
android:layout_width="@dimen/fieldMoyenWidth"
android:layout_height="wrap_content"
android:maxLength="10"
android:layout_marginRight="@dimen/marginRightScreen"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/dateFinConstr"
style="@style/ImpotsStyleLabel"
/>
<EditText
android:id="@+id/dateFinConstr"
android:layout_width="@dimen/fieldMoyenWidth"
android:layout_height="wrap_content"
android:maxLength="10"
android:layout_marginRight="@dimen/marginRightScreen"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="@dimen/marginLeftFieldset"
android:layout_marginRight="@dimen/marginRightFieldset"
android:layout_marginBottom="@dimen/margingBottomFieldset"
android:paddingTop="@dimen/paddingTopFieldset"
android:background="@drawable/fieldset">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/quartier"
style="@style/ImpotsStyleLabel"
/>
<EditText
android:id="@+id/quartier"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/marginRightScreen"
android:inputType="text"
android:enabled="false"
android:focusable="false" />
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/ruePpale"
style="@style/ImpotsStyleLabel"
/>
<Spinner
android:id="@+id/ruePpale"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/marginRightScreen">
</Spinner>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:gravity="center_vertical"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/rueSecnd"
style="@style/ImpotsStyleLabel"
/>
<Spinner
android:id="@+id/rueSecnd"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginRight="@dimen/marginRightScreen">
</Spinner>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/portePpale"
style="@style/ImpotsStyleLabel"
/>
<EditText
android:id="@+id/portePpale"
android:layout_width="@dimen/fieldMoyenWidth"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLength="25"
android:layout_marginRight="@dimen/marginRightScreen"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/porteSecnd"
style="@style/ImpotsStyleLabel"
/>
<EditText
android:id="@+id/porteSecnd"
android:layout_width="@dimen/fieldMoyenWidth"
android:layout_height="wrap_content"
android:inputType="text"
android:maxLength="25"
android:layout_marginRight="@dimen/marginRightScreen"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="vertical"
android:layout_marginLeft="@dimen/marginLeftFieldset"
android:layout_marginRight="@dimen/marginRightFieldset"
android:layout_marginBottom="@dimen/margingBottomFieldset"
android:paddingTop="@dimen/paddingTopFieldset"
android:background="@drawable/fieldset">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/superfBatie"
style="@style/ImpotsStyleLabel"
/>
<EditText
android:id="@+id/superfBatie"
android:layout_width="@dimen/fieldMoyenWidth"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:maxLength="25"
android:layout_marginRight="@dimen/marginRightScreen"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/superfNonBatie"
style="@style/ImpotsStyleLabel"
/>
<EditText
android:id="@+id/superfNonBatie"
android:layout_width="@dimen/fieldMoyenWidth"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:maxLength="25"
android:layout_marginRight="@dimen/marginRightScreen"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/superfTotale"
style="@style/ImpotsStyleLabel"
/>
<EditText
android:id="@+id/superfTotale"
android:layout_width="@dimen/fieldMoyenWidth"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:focusable="false"
android:enabled="false"
android:layout_marginRight="@dimen/marginRightScreen"/>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal">
<TextView
android:layout_width="wrap_content"
android:layout_height="wrap_content"
android:text="@string/superfPlanim"
style="@style/ImpotsStyleLabel"
/>
<EditText
android:id="@+id/superfPlanim"
android:layout_width="@dimen/fieldMoyenWidth"
android:layout_height="wrap_content"
android:inputType="numberDecimal"
android:maxLength="25"
android:layout_marginRight="@dimen/marginRightScreen"/>
</LinearLayout>
</LinearLayout>
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:orientation="horizontal"
android:gravity="center"
android:layout_marginLeft="@dimen/marginLeftFieldset"
android:layout_marginRight="@dimen/marginRightFieldset"
android:layout_marginBottom="@dimen/margingBottomFieldset"
android:paddingTop="@dimen/paddingTopFieldset">
<Button
android:id="@+id/cancel"
android:layout_width="@dimen/buttonWidth"
android:layout_height="wrap_content"
android:text="@string/button_cancel"
android:onClick="fermer" />
<Button
android:id="@+id/ok"
android:layout_width="@dimen/buttonWidth"
android:layout_height="wrap_content"
android:text="@string/button_ok"
android:onClick="valider" />
</LinearLayout>
</LinearLayout>
</ScrollView>
</LinearLayout>
包含的layout
id = tabContentBatiments:
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="match_parent"
android:layout_height="match_parent"
style="@style/ImpotsStyle"
android:orientation="vertical">
<LinearLayout
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:layout_marginLeft="@dimen/marginLeftFieldset"
android:paddingTop="@dimen/margingBottomFieldset"
android:orientation="horizontal">
<Button
android:text="@string/btnLabelAjouter"
android:layout_width="@dimen/buttonWidth"
android:layout_height="wrap_content"
android:layout_gravity="left"
android:onClick="addBatiment"
/>
</LinearLayout>
<ListView
android:layout_width="fill_parent"
android:layout_height="0dip"
android:id="@android:id/list"
android:divider="@drawable/list_divider"
android:dividerHeight="@dimen/divider_height"
android:layout_weight="1"/>
</LinearLayout>
我尝试将content
的{{1}}设置为TabSpec
,但这会导致应用程序崩溃!那么如何将数据或额外内容传递给intent
的两个布局/活动content
?
答案 0 :(得分:-1)
好的,我提出了一个旧提示来解决它:我在public static
中创建了一个Activity
类变量,它调用了tabHost活动。