Android 在选项卡上开始活动单击

Android 在选项卡上开始活动单击,android,tabs,Android,Tabs,我有3个选项卡,单击后显示不同的内容。我希望他们在单击时打开某些活动。这些活动只是需要显示的数据库报告。我使用了web view,在API级别为11的emulator上运行良好,但在API级别为10的设备上出现了一个错误,即未找到网页。此外,这些选项卡仅在单击其他选项卡并返回到第一个选项卡后才显示数据。 有没有一种方法可以直接启动活动而不是使用web view 感谢您的帮助 xml: <LinearLayout android:layout_width="match_parent

我有3个选项卡,单击后显示不同的内容。我希望他们在单击时打开某些活动。这些活动只是需要显示的数据库报告。我使用了web view,在API级别为11的emulator上运行良好,但在API级别为10的设备上出现了一个错误,即
未找到网页。此外,这些选项卡仅在单击其他选项卡并返回到第一个选项卡后才显示数据。
有没有一种方法可以直接启动活动而不是使用web view

感谢您的帮助

xml

<LinearLayout 
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical" >
   <TabHost 
       android:id="@+id/tabhost"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
       >

    <LinearLayout 
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/linearLayout1"
        android:orientation="vertical"
        >
    <TabWidget
        android:id="@android:id/tabs"
        android:layout_width="match_parent"
        android:layout_height="wrap_content" ></TabWidget>
    <FrameLayout 
        android:id="@android:id/tabcontent"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <LinearLayout 
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/tabs1"
            android:orientation="vertical"
            >
            <WebView
                android:id="@+id/txtGetFuelInfo"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="Get info from Database" />
                <TextView
android:id="@+id/txtGetFuel"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"/>
        </LinearLayout>
        <LinearLayout 
              android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/tabs2"
            android:orientation="vertical"
            >

          <WebView
                android:id="@+id/txtMainGetInfo"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="Get info from Database"/>
<TextView
                android:id="@+id/txtGetMain"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"/>


        </LinearLayout>

        <LinearLayout 
             android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:id="@+id/tabs3"
            android:orientation="vertical"
            >
            <WebView
                android:id="@+id/txtSpareGetInfo"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"
                android:text="Get info from Database"/>
<TextView
android:id="@+id/txtGetspare"
                android:layout_width="fill_parent"
                android:layout_height="fill_parent"/>

        </LinearLayout>
    </FrameLayout>
    </LinearLayout>
   </TabHost>
</LinearLayout>

TabHost已被弃用,为什么不使用ActionBar

不管怎样,我想你应该用TabHost之类的东西

Resources ressources = getResources(); 
    TabHost tabHost = getTabHost(); 

    // Android tab
    Intent intentAndroid = new Intent().setClass(this, AndroidActivity.class);
    TabSpec tabSpecAndroid = tabHost
      .newTabSpec("Android")
      .setIndicator("", ressources.getDrawable(R.drawable.icon_android_config))
      .setContent(intentAndroid);
这有一个很好的教程

试试这个

    tabHost = (TabHost) findViewById(android.R.id.tabhost);

    TabSpec Spec = null;
    Spec = tabHost.newTabSpec("home");
    Spec.setIndicator("Home", getResources().getDrawable(R.drawable.ic_tab_home));
    Spec.setContent(new Intent(this, MainList.class));
    tabHost.addTab(Spec);

    Spec = tabHost.newTabSpec("recent");
    Spec.setIndicator("Recent", getResources().getDrawable(R.drawable.ic_tab_recent));
    Spec.setContent(new Intent(this, Recent.class));
    tabHost.addTab(Spec);

    Spec = tabHost.newTabSpec("setting");
    Spec.setIndicator("Setting", getResources().getDrawable(R.drawable.ic_tab_setting));
    Spec.setContent(new Intent(this, Setting.class));
    tabHost.addTab(Spec);

    tabHost.getTabWidget().setCurrentTab(0);

禁止使用Tabhost,以便更好地使用片段。
    tabHost = (TabHost) findViewById(android.R.id.tabhost);

    TabSpec Spec = null;
    Spec = tabHost.newTabSpec("home");
    Spec.setIndicator("Home", getResources().getDrawable(R.drawable.ic_tab_home));
    Spec.setContent(new Intent(this, MainList.class));
    tabHost.addTab(Spec);

    Spec = tabHost.newTabSpec("recent");
    Spec.setIndicator("Recent", getResources().getDrawable(R.drawable.ic_tab_recent));
    Spec.setContent(new Intent(this, Recent.class));
    tabHost.addTab(Spec);

    Spec = tabHost.newTabSpec("setting");
    Spec.setIndicator("Setting", getResources().getDrawable(R.drawable.ic_tab_setting));
    Spec.setContent(new Intent(this, Setting.class));
    tabHost.addTab(Spec);

    tabHost.getTabWidget().setCurrentTab(0);