Question

I am learning to make Tab based apps in android.Got a “you must specify a way to create tab indicator” error in LogCat.

Heres the code......

.java file......

package com.example.tabdemo;

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


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

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

        TabHost tabhost=getTabHost();

        TabHost.TabSpec spec1=tabhost.newTabSpec("Tab 1");
        Intent intent1=new Intent(this, Tabone.class);
        spec1.setContent(intent1);
       // spec1.setIndicator("Tab 1", getResources().getDrawable(R.drawable.face));
        spec1.setIndicator("Tab 1");
        tabhost.addTab(spec1);

        TabHost.TabSpec spec2=tabhost.newTabSpec("Tab 2");
        Intent intent2=new Intent(this,Tabtwo.class);
        spec2.setContent(intent2);
     //   spec1.setIndicator("Tab 2", getResources().getDrawable(R.drawable.face));
        spec1.setIndicator("Tab 2");


        tabhost.addTab(spec2);
        tabhost.setCurrentTab(1);
    }
}

activity xml file...

<?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="fill_parent"
    android:layout_height="fill_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="fill_parent"/> 
    </LinearLayout> 
</TabHost>
Was it helpful?

Solution

You didn't set indicator for the tab2

check your code

spec2.setContent(intent2);
 //   spec1.setIndicator("Tab 2", getResources().getDrawable(R.drawable.face));
    spec1.setIndicator("Tab 2");

you overwrite your tab1 indicator.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top