Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7801189
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 2, 20262026-06-02T00:52:08+00:00 2026-06-02T00:52:08+00:00

I have a little problem using Tabs with Views. First I just copied the

  • 0

I have a little problem using Tabs with Views.
First I just copied the sample code where Tabs are used with activitys:

My LayoutFile looks like this:

<?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"
        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" />
    </LinearLayout>
</TabHost>

And this is my Java-code:

public class MyActivity extends TabActivity{
    public void onCreate(Bundle savedInstanceState){
        super.onCreate(savedInstanceState)
        setContentView(R.layout.main);
        TabHost tH = getTabHost();

        Indent intent = new Intent().setClass(this, AnotherActivity.class);

        // Initialize a TabSpec for each tab and add it to the TabHost
        //TextView Test = new TextView(this);
        //Test.setText("test");

        tH.addTab(tH.newTabSpec("t1").setIndicator("Tab1").setContent(intent));
        tH.setCurrentTab(0);
    }
}

And this works as expected.
But when I uncomment the TextView-lines and call setContent(Test.getId()) instead of setContent(intent), the app crashes.
I also tried to create a textview in the layoutfile, and call setContent(R.id.test),
that also makes it crash.

So this is one problem.

The seccond point is. I do not want to use activitys, because i want to be able to call methods on those classes, which shall represent the Tab-content.
So my original idea is, to derive some classes from view. 1 for each tab, and pass their ids. But therefor the codesample above needs to work first.

greetings Uzaku

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-02T00:52:09+00:00Added an answer on June 2, 2026 at 12:52 am

    I know you said you tried a TextView in the layout file but this should work…

    Change the FrameLayout section as follows…

    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:padding="5dp" >
        <TextView 
            android:id="@+id/test"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent" 
            android:text="TEST" />
    </FrameLayout>
    

    Then in your code do the following…

    tH.addTab(tH.newTabSpec("t1").setIndicator("Tab1").setContent(R.id.test));
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm using ActionBarSherlock and have a little problem. In the Fragment Tabs example, there
I have a little problem about using jQuery (I really do not know jQuery
I have a little problem with a query. I'm selecting data using the between
I have a little problem with adding actions on UITabBarItems. I am not using
I have a little problem, probably easy for you. Im using Core Data. I
I have a little demonstration below of a peculiar problem. using System; using System.Windows.Forms;
i have little problem in using my application application having msaccess database if i
I have got a little problem using the CodeIgniter route function. I use the
I have a little problem. When I'm using DataContractJsonSerializer with complex types(own types) it
I have a little problem using Suds in Django (1.3, python 2.7). When I

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.