Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
504 views
in Technique[技术] by (71.8m points)

android - Can't find the cause "you must specify a way to create the tab indicator"

I am getting "you must specify a way to create the tab indicator" error(as per logcat). Can't find the reason.

Main class:

package org.tatvamoksh.tml;


import android.app.TabActivity; 
import android.content.Intent;
import android.os.Bundle;
import android.view.Window;
import android.widget.TabHost;
import android.widget.TabHost.TabSpec;

@SuppressWarnings({ "deprecation" })
public class MainActivity extends TabActivity {

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    //Remove title bar
    this.requestWindowFeature(Window.FEATURE_NO_TITLE);

    setContentView(R.layout.activity_main);

    TabHost tabHost = getTabHost();

    // Tab for Tatva
    TabSpec t = tabHost.newTabSpec("Tatva");
    // setting Title and Icon for the Tab
    t.setIndicator("Tatva");
    Intent tatvaIntent = new Intent(this, TatvaActivity.class);
    t.setContent(tatvaIntent);

    // Tab for Moksh
    TabSpec m = tabHost.newTabSpec("Moksh");
    m.setIndicator("Moksh");
    Intent mokshIntent = new Intent(this, MokshActivity.class);
    m.setContent(mokshIntent);

    //Tab for Updates
    TabSpec u = tabHost.newTabSpec("Updates");
    m.setIndicator("Updates");
    Intent updatesIntent = new Intent(this, Updates.class);
    m.setContent(updatesIntent);

    // Adding all TabSpec to TabHost
    tabHost.addTab(t); // Adding Tatva tab
    tabHost.addTab(m); // Adding Moksh tab
    tabHost.addTab(u); // Adding Updates tab
}
}

layout file:

<RelativeLayout 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"
tools:context=".MainActivity" >

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

    <LinearLayout
   android:layout_width="match_parent"
   android:layout_height="match_parent"
   android:orientation="vertical" >

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

        <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="match_parent"
        android:layout_height="match_parent" >

            <ListView
            android:id="@android:id/list"
            android:layout_width="match_parent"
            android:layout_height="match_parent" >
            </ListView>
        </FrameLayout>
    </LinearLayout>
</TabHost>
</RelativeLayout>

Commenting out the following code fixes it.

       //Tab for Updates
    TabSpec u = tabHost.newTabSpec("Updates");
    m.setIndicator("Updates");
    Intent updatesIntent = new Intent(this, Updates.class);
    m.setContent(updatesIntent);

I can't guess the exact problem. Would be grateful for any guidance.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

change last tab code as :

//Tab for Updates
    TabSpec u = tabHost.newTabSpec("Updates");
    u.setIndicator("Updates");
    Intent updatesIntent = new Intent(this, Updates.class);
    u.setContent(updatesIntent);

because you are not setting Indicator and Content for TabSpec u (you are setting for m Tab)


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...