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

  • Home
  • SEARCH
  • 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 587821
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 13, 20262026-05-13T15:15:11+00:00 2026-05-13T15:15:11+00:00

This is what i’m trying to achieve: Use a TextView in a TabWidget (i.e.

  • 0

This is what i’m trying to achieve:

  1. Use a TextView in a TabWidget (i.e. call TabHost.TabSpec.setIndicator(View) instead of TabHost.TabSpec.setIndicator(String)).

  2. And i want to configure that TextView in XML instead of building it programatically.

So initially, in my layout XML, i had:

<TabHost
    android:id="@+id/mainTabHost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="30px"/>
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:paddingTop="30px">
    </FrameLayout>
</TabHost>

Now i want to put in the TextView configuration somewhere. It does not actually “belong” nested anywhere within the layout hierarchy. But, since the layout XML have to be a valid XML of course, it can’t have more than one root element. So i’m forced to nest the TextView somewhere. Hence i just put it one level below the root (TabHost):

<TabHost
    android:id="@+id/mainTabHost"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    xmlns:android="http://schemas.android.com/apk/res/android">
    <TabWidget android:id="@android:id/tabs" android:layout_width="fill_parent" android:layout_height="30px"/>
    <TextView
        android:id="@+id/tvTabIndicatorPreferences"
        android:layout_width="wrap_content"
        android:layout_height="fill_parent"
        android:text="@string/tab_name_preferences"/>
    <FrameLayout
        android:id="@android:id/tabcontent"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:paddingTop="30px">
    </FrameLayout>
</TabHost>

And in my code i do:

final TabHost mainTabHost = (TabHost) this.findViewById(R.id.mainTabHost);
mainTabHost.setup();
final TextView tvTabIndicatorPreferences = (TextView) this.findViewById(R.id.tvTabIndicatorPreferences);
final TabHost.TabSpec tabSpecPreferences = mainTabHost.newTabSpec("tabPreferences");
tabSpecPreferences.setIndicator(tvTabIndicatorPreferences);
tabSpecPreferences.setContent(R.id.scrlTblPreferences);
mainTabHost.addTab(tabSpecPreferences);

but there’s a problem here. When i try to run the application, i get an exception which says

Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.

which is by all means logical and reasonable. The TextView is already a child of the TabHost. i can’t just set it as the child of another element. (Note: Putting the TextView nested under the TabWidget yields the same thing.)

so i’m forced to call mainTabHost.removeView(tvTabIndicatorPreferences) before calling the setIndicator.

It works actually, but this way of doing feels very wrong to me. Firstly, i have to put the TextView in the XML where it didn’t belong, then in the code remove it from where it didn’t belong before using it.

In such a scenario, what’s the Right Way to achieve this?

  • 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-13T15:15:12+00:00Added an answer on May 13, 2026 at 3:15 pm

    Step #1: Pull the TextView out into a separate layout file (e.g., res/layout/indicator.xml).

    Step #2: Call tabSpecPreferences.setIndicator(getLayoutInflater().inflate(R.layout.indicator, null));

    Step #3: There is no Step #3.

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

Sidebar

Ask A Question

Stats

  • Questions 318k
  • Answers 318k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer You get this with Sybase when the system is restarted… May 13, 2026 at 11:55 pm
  • Editorial Team
    Editorial Team added an answer Use NSInvocation. NSInvocation* invoc = [NSInvocation invocationWithMethodSignature: [cell methodSignatureForSelector: @selector(initWithFrame:reuseIdentifier:)]];… May 13, 2026 at 11:55 pm
  • Editorial Team
    Editorial Team added an answer Place this in the button click event Dim int As… May 13, 2026 at 11:55 pm

Related Questions

I ran into a problem. Wrote the following code snippet: teksti = teksti.Trim() teksti
this is what i have right now Drawing an RSS feed into the php,
I am currently running into a problem where an element is coming back from
I have text I am displaying in SIlverlight that is coming from a CMS
Is it possible to replace javascript w/ HTML if JavaScript is not enabled on

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

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.