2

Here is the xml for tab host I don't think the error is here but still..

<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"
    android:background="@color/negru"
    android:orientation="vertical" >

    <TextView
        android:id="@+id/scoreId"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:gravity="center"
        android:text="@string/scores"
        android:textColor="@color/galben"
        android:textSize="@dimen/menuDim" />

    <TabHost
        android:id="@+id/tabhost"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent" >

        <LinearLayout
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:orientation="vertical"
            android:padding="5dp" >

            <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="fill_parent"
                android:padding="5dp" >

                <include
                    android:id="@+id/cell1"
                    layout="@layout/cel1" />

                <include
                    android:id="@+id/cell2"
                    layout="@layout/cel1" />
            </FrameLayout>
        </LinearLayout>
    </TabHost>

</LinearLayout>

here is java file containing the tabhost setup i think here i have a mistake at initializing the tabhost but i can't figure it out

@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_scores);

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

    tabHost.setup();

    TabSpec allScore = tabHost.newTabSpec("allTab");
    allScore.setIndicator("allTab");
    allScore.setContent(R.id.cell1);
    tabHost.addTab(allScore);

    TabSpec friendScore = tabHost.newTabSpec("friendTab");
    allScore.setIndicator("friendTab");
    allScore.setContent(R.id.cell2);
    tabHost.addTab(friendScore);

    tabHost.setCurrentTabByTag("allTab");

}

and cell1 layout used for show in cells

<?xml version="1.0" encoding="utf-8"?>
<ScrollView xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/scrollAllScore"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    android:scrollbars="vertical" >

    <TableLayout
        android:id="@+id/AllScore"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content"
        android:stretchColumns="*" >
        <TableRow 
            >
            <TextView 
                android:text="@string/app_name"/>
        </TableRow>
        <TableRow 
            >
            <TextView 
                android:text="@string/app_name"/>
        </TableRow>
    </TableLayout>
</ScrollView>

this is the debug info

Thread [<1> main] (Suspended (exception RuntimeException))  
    <VM does not provide monitor information>   
    ActivityThread.performLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1664    
    ActivityThread.handleLaunchActivity(ActivityThread$ActivityClientRecord, Intent) line: 1680 
    ActivityThread.access$1500(ActivityThread, ActivityThread$ActivityClientRecord, Intent) line: 117   
    ActivityThread$H.handleMessage(Message) line: 931   
    ActivityThread$H(Handler).dispatchMessage(Message) line: 99 
    Looper.loop() line: 130 
    ActivityThread.main(String[]) line: 3703    
    Method.invokeNative(Object, Object[], Class, Class[], Class, int, boolean) line: not available [native method]  
    Method.invoke(Object, Object...) line: 507  
    ZygoteInit$MethodAndArgsCaller.run() line: 841  
    ZygoteInit.main(String[]) line: 599 
    NativeStart.main(String[]) line: not available [native method]  

Please help me out I really can't see what is wrong!

4

2 回答 2

0

错误就在这里

TabSpec allScore = tabHost.newTabSpec("allTab");
    allScore.setIndicator("allTab");
    allScore.setContent(R.id.cell1);
    tabHost.addTab(allScore);

    TabSpec friendScore = tabHost.newTabSpec("friendTab");
    allScore.setIndicator("friendTab");
    allScore.setContent(R.id.cell2);
    tabHost.addTab(friendScore);

我忘记将 tabspec 变量名称从 allscore 更改为 Friendscore

于 2012-09-15T10:16:23.460 回答
0

尝试更改根标签:

<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" >

可能是他的问题。

于 2012-09-12T17:36:16.093 回答