Android tabhost的选项卡(活动)不显示任何内容

Android tabhost的选项卡(活动)不显示任何内容,android,android-listview,android-activity,runtime-error,android-tabhost,Android,Android Listview,Android Activity,Runtime Error,Android Tabhost,该应用程序有5个选项卡,第一个选项卡的布局中只有一个文本视图,其他选项卡的布局与ListView相同,但在选项卡中没有显示任何内容,只有一个白色背景 下面是一些日志和代码: 控制台: ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=tbf.tb.simulador1o1/.MainActivity } ActivityMana

该应用程序有5个选项卡,第一个选项卡的布局中只有一个文本视图,其他选项卡的布局与ListView相同,但在选项卡中没有显示任何内容,只有一个白色背景

下面是一些日志和代码:

控制台:

ActivityManager: Starting: Intent { act=android.intent.action.MAIN cat=[android.intent.category.LAUNCHER] cmp=tbf.tb.simulador1o1/.MainActivity }
ActivityManager: Warning: Activity not started, its current task has been brought to the front
日志:

11-24 18:13:11.211: D/dalvikvm(1790): GC_FOR_ALLOC freed 392K, 10% free 9501K/10476K, paused 97ms, total 121ms
11-24 18:13:11.341: D/dalvikvm(1790): GC_FOR_ALLOC freed 6863K, 68% free 3848K/11688K, paused 41ms, total 42ms
11-24 18:13:11.341: I/dalvikvm-heap(1790): Grow heap (frag case) to 4.559MB for 696976-byte allocation
11-24 18:13:11.471: D/dalvikvm(1790): GC_FOR_ALLOC freed <1K, 62% free 4528K/11688K, paused 119ms, total 119ms
11-24 18:13:11.551: D/dalvikvm(1790): GC_CONCURRENT freed 0K, 62% free 4528K/11688K, paused 16ms+17ms, total 87ms
11-24 18:13:11.672: D/dalvikvm(1790): GC_FOR_ALLOC freed <1K, 62% free 4528K/11688K, paused 46ms, total 46ms
11-24 18:13:11.672: I/dalvikvm-heap(1790): Grow heap (frag case) to 5.739MB for 1238176-byte allocation
11-24 18:13:11.751: D/dalvikvm(1790): GC_CONCURRENT freed 0K, 51% free 5737K/11688K, paused 10ms+16ms, total 81ms
11-24 18:13:11.921: D/dalvikvm(1790): GC_FOR_ALLOC freed 1032K, 52% free 5683K/11688K, paused 39ms, total 41ms
11-24 18:13:12.111: D/dalvikvm(1790): GC_FOR_ALLOC freed 352K, 47% free 6309K/11688K, paused 38ms, total 39ms
11-24 18:13:12.231: D/dalvikvm(1790): GC_FOR_ALLOC freed 352K, 41% free 6934K/11688K, paused 38ms, total 39ms
11-24 18:13:12.482: D/dalvikvm(1790): GC_FOR_ALLOC freed 352K, 33% free 7913K/11688K, paused 41ms, total 42ms
11-24 18:13:36.001: I/Choreographer(1790): Skipped 57 frames!  The application may be doing too much work on its main thread.
表2布局:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent">

    <ListView android:id="@android:id/list"
        android:layout_width="fill_parent" 
        android:layout_height="fill_parent"
        android:layout_weight="0" >
    </ListView>
</LinearLayout>

表2类别:

public class Tab_2 extends Activity {
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_tab);

        // Create Parser for raw/list_combo_offer.xml
        ItemParser itemParser = new ItemParser();
        InputStream inputStream = getResources().openRawResource(
                R.raw.list_tab2);

        // Parse the inputstream
        itemParser.parse(inputStream);

        // Get items
        List<Item> itemList = itemParser.getList();

        // Create a customized ArrayAdapter
        ItemArrayAdapter adapter = new ItemArrayAdapter(
                this, //getApplicationContext(), 
                R.layout.item_list, 
                itemList);

        ListView lv = (ListView) findViewById(android.R.id.list);
        lv.setAdapter(adapter);
        lv.setOnItemClickListener(new OnItemClickListener()
        {
             @Override
             public void onItemClick(AdapterView<?> a, View v, int position, long id) 
             {
                 Intent intent = new Intent(Tab_2.this, ItemActivity.class);
                 intent.putExtra("position", (int) position);
                 startActivity(intent);
             }
        });

    }
}
公共类选项卡2扩展活动{
创建时的公共void(Bundle savedInstanceState){
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_选项卡);
//为raw/list\u combo\u offer.xml创建解析器
ItemParser ItemParser=新的ItemParser();
InputStream InputStream=getResources().openRawResource(
R.原始列表(表2);
//解析输入流
parse(inputStream);
//获取项目
List itemList=itemParser.getList();
//创建自定义的ArrayAdapter
ItemArrayAdapter=新的ItemArrayAdapter(
这,//getApplicationContext(),
R.布局。项目清单,
项目清单);
ListView lv=(ListView)findViewById(android.R.id.list);
低压设置适配器(适配器);
lv.setOnItemClickListener(新的OnItemClickListener()
{
@凌驾
公共视图单击(适配器视图a、视图v、内部位置、长id)
{
意向意向=新意向(Tab_2.this,ItemActivity.class);
意向。额外(“位置”,“内部”位置);
星触觉(意向);
}
});
}
}
AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="tbf.tb.simulador1o1"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="tbf.tb.simulador1o1.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="tbf.tb.simulador1o1.Tab_1"
            android:label="@string/tab_1"
            android:parentActivityName="tbf.tb.simulador1o1.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="tbf.tb.simulador1o1.MainActivity" />
        </activity>

        <activity
            android:name="tbf.tb.simulador1o1.Tab_2"
            android:label="@string/tab_2"
            android:parentActivityName="tbf.tb.simulador1o1.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="tbf.tb.simulador1o1.MainActivity" />
        </activity>

        <activity
            android:name="tbf.tb.simulador1o1.Tab_3"
            android:label="@string/tab_3"
            android:parentActivityName="tbf.tb.simulador1o1.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="tbf.tb.simulador1o1.MainActivity" />
        </activity>

        <activity
            android:name="tbf.tb.simulador1o1.Tab_4"
            android:label="@string/tab_4"
            android:parentActivityName="tbf.tb.simulador1o1.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="tbf.tb.simulador1o1.MainActivity" />
        </activity>

        <activity
            android:name="tbf.tb.simulador1o1.Tab_5"
            android:label="@string/tab_5"
            android:parentActivityName="tbf.tb.simulador1o1.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="tbf.tb.simulador1o1.MainActivity" />
        </activity>

    </application>

</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="tbf.tb.simulador1o1"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="tbf.tb.simulador1o1.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name="tbf.tb.simulador1o1.Tab_1"/>
        <activity android:name="tbf.tb.simulador1o1.Tab_2"/>
        <activity android:name="tbf.tb.simulador1o1.Tab_3"/>
        <activity android:name="tbf.tb.simulador1o1.Tab_4"/>
        <activity android:name="tbf.tb.simulador1o1.Tab_5"/>
        <activity android:name="tbf.tb.simulador1o1.ItemActivity"/>

    </application>

</manifest>

修复

主要活动布局:

<?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="match_parent"
        android:layout_height="match_parent">

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"/>

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="0dp"
            android:layout_height="0dp"
            android:layout_weight="0"/>

        <FrameLayout
            android:id="@+id/realtabcontent"
            android:layout_width="match_parent"
            android:layout_height="0dp"
            android:layout_weight="1"/>

    </LinearLayout>
</TabHost>
<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="match_parent"
        android:layout_height="match_parent">

        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="0dip"
            android:layout_weight="1"/>

        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"
            android:layout_weight="0"
            android:layout_marginBottom="-4dp"/>

    </LinearLayout>
</TabHost>

AndroidManifest:

<?xml version="1.0" encoding="utf-8"?>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="tbf.tb.simulador1o1"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="tbf.tb.simulador1o1.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity
            android:name="tbf.tb.simulador1o1.Tab_1"
            android:label="@string/tab_1"
            android:parentActivityName="tbf.tb.simulador1o1.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="tbf.tb.simulador1o1.MainActivity" />
        </activity>

        <activity
            android:name="tbf.tb.simulador1o1.Tab_2"
            android:label="@string/tab_2"
            android:parentActivityName="tbf.tb.simulador1o1.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="tbf.tb.simulador1o1.MainActivity" />
        </activity>

        <activity
            android:name="tbf.tb.simulador1o1.Tab_3"
            android:label="@string/tab_3"
            android:parentActivityName="tbf.tb.simulador1o1.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="tbf.tb.simulador1o1.MainActivity" />
        </activity>

        <activity
            android:name="tbf.tb.simulador1o1.Tab_4"
            android:label="@string/tab_4"
            android:parentActivityName="tbf.tb.simulador1o1.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="tbf.tb.simulador1o1.MainActivity" />
        </activity>

        <activity
            android:name="tbf.tb.simulador1o1.Tab_5"
            android:label="@string/tab_5"
            android:parentActivityName="tbf.tb.simulador1o1.MainActivity" >
            <meta-data
                android:name="android.support.PARENT_ACTIVITY"
                android:value="tbf.tb.simulador1o1.MainActivity" />
        </activity>

    </application>

</manifest>
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
    package="tbf.tb.simulador1o1"
    android:versionCode="1"
    android:versionName="1.0" >

    <uses-sdk
        android:minSdkVersion="13"
        android:targetSdkVersion="17" />

    <application
        android:allowBackup="true"
        android:icon="@drawable/ic_launcher"
        android:label="@string/app_name"
        android:theme="@style/AppTheme" >

        <activity
            android:name="tbf.tb.simulador1o1.MainActivity"
            android:label="@string/app_name" >
            <intent-filter>
                <action android:name="android.intent.action.MAIN" />

                <category android:name="android.intent.category.LAUNCHER" />
            </intent-filter>
        </activity>

        <activity android:name="tbf.tb.simulador1o1.Tab_1"/>
        <activity android:name="tbf.tb.simulador1o1.Tab_2"/>
        <activity android:name="tbf.tb.simulador1o1.Tab_3"/>
        <activity android:name="tbf.tb.simulador1o1.Tab_4"/>
        <activity android:name="tbf.tb.simulador1o1.Tab_5"/>
        <activity android:name="tbf.tb.simulador1o1.ItemActivity"/>

    </application>

</manifest>