2

5 つの EditText ウィジェットが最初のタブに配置され、5 つの EditText ウィジェットが 2 番目のタブに配置され、5 つの EditText ウィジェットが 3 番目のタブに配置されています。ここで、単一のボタンをクリックして、すべてのタブのデータをデータベースに追加したいと考えています。ボタンがタブ レイアウト内にありません。線形レイアウトの内部... xml ツリー構造は次のようになります。

<?xml version="1.0" encoding="utf-8"?>
<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:background="#ffffff" >
    <LinearLayout
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:orientation="vertical" >
        <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="300dp" >
        </FrameLayout>
                 <Button
                     android:id="@+id/submit"
                     android:layout_width="match_parent"
                     android:layout_height="wrap_content"
                     android:text="Submit" />
    </LinearLayout>
</TabHost>
4

2 に答える 2

1

はい、タブコンテンツの各アクティビティの最後にボタンを配置しないでください。あなたがすることは、3つの別々のアクティビティを取る代わりに、内部サブアクティビティを取らないことです. メインのアクティビティで、すべてのレイアウト (アクティビティのコンテンツ ビューとして設定している) を膨張させ、3 つのタブのコンテンツとして設定します。次に、膨張した3つのビューがあります。ビューのパースペクティブに関して EditTexts オブジェクトを作成し、ボタンをクリックしたときにそれらを使用します。私の考えを理解していただければ幸いです。さらに重要なことに、アクティビティはより多くのメモリを消費するため、タブのコンテンツとしてアクティビティを使用することはお勧めしません。同じことを踏襲しているが欠点を隠しているチュートリアルがたくさんあることは知っています。

于 2012-12-03T14:45:50.703 に答える
0

私は3つの活動を膨らませました。3 つのすべてのアクティビティに EditTexts が含まれています。コードは次のとおりです。

    TabHost tabHost = getTabHost();

    // Tab for Photos
    TabSpec photospec = tabHost.newTabSpec("Photos");
    photospec.setIndicator("General", getResources().getDrawable(R.drawable.icon_photos_tab));
    Intent photosIntent = new Intent(this, PhotosActivity.class);
    photospec.setContent(photosIntent);

    // Tab for Songs
    TabSpec songspec = tabHost.newTabSpec("Songs");
    // setting Title and Icon for the Tab
    songspec.setIndicator("Private", getResources().getDrawable(R.drawable.icon_songs_tab));
    Intent songsIntent = new Intent(this, SongsActivity.class);
    songspec.setContent(songsIntent);

    // Tab for Videos
    TabSpec videospec = tabHost.newTabSpec("Videos");
    videospec.setIndicator("Other", getResources().getDrawable(R.drawable.icon_videos_tab));
    Intent videosIntent = new Intent(this, VideosActivity.class);
    videospec.setContent(videosIntent);


    // Adding all TabSpec to TabHost
    tabHost.addTab(photospec); // Adding photos tab
    tabHost.addTab(songspec); // Adding songs tab
    tabHost.addTab(videospec); // Adding videos tab

3 つのタブすべてに EditText を追加しました。単一のボタンをクリックして、3 つのタブ (EditText を含む) すべてのデータをデータベースに追加したいと考えています。ボタンは main.xml にあり、出力は次のとおりです。

出力は次のようになります

于 2012-12-22T09:25:42.077 に答える