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 6732545
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T10:39:49+00:00 2026-05-26T10:39:49+00:00

This is a problem that has troubled me for a few days now. I’ve

  • 0

This is a problem that has troubled me for a few days now. I’ve done my best searching for a solution, but everywhere I go it says the approach I’m currently using is the right one.

The situation is simple: I have five tabs, which are to contain the same layout with slightly different content (for example by using setText to change one of the labels). As such, I am inflating the layout five times, and adding all of them as seperate tabs.

This is my code:

package com.test;

import android.app.TabActivity;
import android.content.res.Resources;
import android.os.Bundle;
import android.view.View;
import android.widget.TabHost;
import android.widget.TextView;

public class TestActivity extends TabActivity
{
    @Override
    public void onCreate(Bundle savedInstanceState)
    {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        TabHost host = getTabHost();
        Resources res = getResources();

        String[] days = { "Monday", "Tuesday", "Wednesday", "Thursday", "Friday" };

        for (int i = 0; i < days.length; i++)
        {
            View contents = getLayoutInflater().inflate(R.layout.test, host.getTabContentView(), true);

            ((TextView)contents.findViewById(R.id.title)).setText(days[i]);

            host.addTab
            (
                host.newTabSpec(days[i]).
                setIndicator(days[i]).
                setContent(contents.getId())
            );

            host.getTabWidget().getChildAt(i).getLayoutParams().height = 55;
        }
    }
}

And my layout file looks like this:

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

    <TextView
        android:id="@+id/title"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:text="Test"
        android:textAppearance="?android:attr/textAppearanceMedium" />

</LinearLayout>

The problem is that, instead of the text being on seperate tabs, all the text overlaps eachother and is the same for every tab. It might be something really simple that I’m overlooking. Any help is appreciated.

  • 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-05-26T10:39:50+00:00Added an answer on May 26, 2026 at 10:39 am
     all the text overlaps eachother and is the same for every tab
    

    They ain’t overlapping each other from my discovery. If you remove android:text="Test" from your layout file, you will be seeing only Friday in all tab.

    It looks like you will need to use TabContentFactory to achieve what you want. Here is my solution to your problem. It will give you what you needed.

    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
    
        final TabHost host = getTabHost();
        Resources res = getResources();
    
        final String[] days = { "Monday", "Tuesday", "Wednesday", "Thursday",
                "Friday" };
    
        for (int i = 0; i < days.length; i++) {
            TabHost.TabSpec spec=host.newTabSpec(days[i]);
            spec.setContent(new TabHost.TabContentFactory() {
                public View createTabContent(String tag) {
                    View wv = getLayoutInflater().inflate(R.layout.test, host.getTabContentView(), false);
                    ((TextView) wv.findViewById(R.id.title)).setText(tag);
                    return(wv);
                }
            });
            spec.setIndicator(days[i]);
            host.addTab(spec);
        }
        host.setCurrentTab(0);
    }
    

    Here is the link where I get started https://github.com/commonsguy/cw-android/tree/master/Fancy/DynamicTab

    Credit goes to Mark Murphy(Commonsguy).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been having a problem that has troubled me for a while. Searching
There was this problem that has been asked about implementing a load byte into
This is my problem. I have a program that has to run in a
This has been a problem that I haven't been able to figure out for
Edit : The bug that caused this problem has been fixed. The @version tag
Has anyone run into this problem? I have a collection of comments that I
Has anyone else run into this problem before? I've got a method that calls
I have a problem with IE. I have a layer that has this style
Has anyone seen this type of IE display problem? Example http://xs133.xs.to/xs133/08465/ie_problem910.jpg.xs.jpg Note that it
This problem has been bothering me for sometime now, I have not settled on

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.