Error in MainActivity when implementing TabActivity

149 views Asked by At

i want a page with text on top(EditText) then image (in FragmentLayout) and then two tabs below that image. my output is not showing any tab in output but i have written code to implement tabs. this code is notshowing any error and in output i mam not getting any tab in output

i am not getting correct output and this is not even showing any error i tried it without extending TabActivity also (only with extens Activity) but still output is same whose image is loaded above Code of activity_main.xml is

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

     <TextView
        android:id="@+id/tbol"
        android:layout_width="250dp"
        android:layout_height="30dp"
        android:text="@string/heading"
        android:textAppearance="?android:attr/textAppearanceMedium"
        android:textColor="#F00"
        android:textSize="25sp" />

    <FrameLayout
        android:layout_width="match_parent"
        android:layout_height="160dp"
        android:background="@drawable/leaf" >
    </FrameLayout>

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

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

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

     </LinearLayout>

code of MainActivity.java is

package com.example.tabhost;

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

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

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

      th=getTabHost();

      //For desc tab
      TabSpec descspec=th.newTabSpec("Description");
      descspec.setIndicator("Description", null);
      Intent firstintent=new Intent(this, DecsriptionTab.class);
      descspec.setContent(firstintent);

    //For Information Tab
    TabSpec infospec=th.newTabSpec("Information");
    infospec.setIndicator("Information", null);
    Intent secondintent=new Intent(this, Info_Tab.class);
    descspec.setContent(secondintent);

   }

  }

this is code of 2 .xml files

desc_layout.xml

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
     xmlns:android="http://schemas.android.com/apk/res/android">

     <TextView android:text="This is desc tab"
            android:padding="15dp"
            android:textSize="18sp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>

</LinearLayout>

info_layout

<?xml version="1.0" encoding="UTF-8"?>
<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical"
     xmlns:android="http://schemas.android.com/apk/res/android">

     <TextView android:text="This is info tab"
            android:padding="15dp"
            android:textSize="18sp"
            android:layout_width="fill_parent"
            android:layout_height="wrap_content"/>

</LinearLayout>

This is code of corresponding java files

DecsriptionTab.java

package com.example.tabhost;

import android.app.Activity;
import android.os.Bundle;

public class DecsriptionTab extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.desc_layout);
    }

  }

Info_Tab.java

package com.example.tabhost;

import android.app.Activity;
import android.os.Bundle;

public class Info_Tab extends Activity {

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);
        setContentView(R.layout.info_layout);
    }


}
0

There are 0 answers