1

合計3つのアクティビティを持つ単純なアプリケーションを作成しています

  1. サインイン-ユーザー名、パスワードフィールド、サインインおよびサインアップボタンがあります
  2. サインアップ-さまざまなフォームフィールドと送信ボタンがあります
  3. メッセージ - サインインに成功すると、このアクティビティに移動します

上記の 3 つのアクティビティを定義する 3 つのタブを持つ tabhost を使用します。タブをクリックすると、それぞれのアクティビティを切り替えることができますが、フォームのボタンを使用して切り替えると、タブが表示されません。タブまたはボタンから切り替えて、画面にタブを表示したい。タブのレイアウトを維持し、フレーム内のアクティビティのみを変更するような概念はありますか...タブホストグループについて聞いたことがありますが、それを使用できません...それで可能ですか. タンク・ユー

私のタブホストコードは

public class TabActivity extends android.app.TabActivity
{
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab);

      /** TabHost will have Tabs */ 
    TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost); 

    /** TabSpec used to create a new tab.  
     * By using TabSpec only we can able to setContent to the tab.  
     * By using TabSpec setIndicator() we can set name to tab. */

    /** tid1 is firstTabSpec Id. Its used to access outside. */ 
    TabSpec signinTab = tabHost.newTabSpec("tid1");  
    TabSpec signupTab = tabHost.newTabSpec("tid2"); 
    TabSpec messageTab = tabHost.newTabSpec("tid3");

    /** TabSpec setIndicator() is used to set name for the tab. */ 
    /** TabSpec setContent() is used to set content for a particular tab. */ 
    signinTab.setIndicator("Sign In").setContent(new Intent(getApplicationContext(),SignIn.class));  
    signupTab.setIndicator("Sign Up").setContent(new Intent(getApplicationContext(),MainActivity.class));
    messageTab.setIndicator("Message").setContent(new Intent(getApplicationContext(),MessageDisplay.class));

    /** Add tabSpec to the TabHost to display. */ 
    tabHost.addTab(signinTab);  
    tabHost.addTab(signupTab); 
    tabHost.addTab(messageTab);//set Windows tab as default (zero based)

  // tabHost.setCurrentTab(2);
}

}
4

1 に答える 1

1

Java コード:

public class TabActivity extends android.app.TabActivity
{
public void onCreate(Bundle savedInstanceState) 
{
    super.onCreate(savedInstanceState);
    setContentView(R.layout.tab);

      /** TabHost will have Tabs */ 
    TabHost tabHost = getTabHost();

    /** TabSpec used to create a new tab.  
     * By using TabSpec only we can able to setContent to the tab.  
     * By using TabSpec setIndicator() we can set name to tab. */

    /** tid1 is firstTabSpec Id. Its used to access outside. */ 
    TabSpec signinTab = tabHost.newTabSpec("tid1");  
    TabSpec signupTab = tabHost.newTabSpec("tid2"); 
    TabSpec messageTab = tabHost.newTabSpec("tid3");

    /** TabSpec setIndicator() is used to set name for the tab. */ 
    /** TabSpec setContent() is used to set content for a particular tab. */ 
    signinTab.setIndicator("Sign In").setContent(new Intent(getApplicationContext(),SignIn.class));  
    signupTab.setIndicator("Sign Up").setContent(new Intent(getApplicationContext(),MainActivity.class));
    messageTab.setIndicator("Message").setContent(new Intent(getApplicationContext(),MessageDisplay.class));

    /** Add tabSpec to the TabHost to display. */ 
    tabHost.addTab(signinTab);  
    tabHost.addTab(signupTab); 
    tabHost.addTab(messageTab);//set Windows tab as default (zero based)

  // tabHost.setCurrentTab(2);
}

}

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="match_parent"
    android:layout_height="match_parent" >
    <LinearLayout
        android:orientation="vertical"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent">

        <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="wrap_content"/>


    </LinearLayout>
</TabHost>
于 2012-10-23T09:58:56.740 に答える