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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 29, 20262026-05-29T19:04:47+00:00 2026-05-29T19:04:47+00:00

I’m trying to insert a ListView as one of the tabs in a tabhost.

  • 0

I’m trying to insert a ListView as one of the tabs in a tabhost. I’ve scoured the web and found several implementations that say they work, but don’t for me (either in their own projects or when incorporated into mine).

I’ve settled on the following, which works (as far as not crashing) and I’m not getting any errors in LogCat, but the tab appears empty.

I’ve checked the array supplying the list (tooldisplay) and it is populated.

I would rather not have to fire another activity to populate the tab.

setupdetail.xml:

<?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:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical"
        android:padding="5dp" >
        <TextView
            android:id="@+id/setupheader"
            android:layout_width="fill_parent"
            android:layout_height="20dp"
            android:text="This will be the setup header"
            android:textSize="15dp" />
        <TabWidget
            android:id="@android:id/tabs"
            android:layout_width="fill_parent"
            android:layout_height="30dp"
            android:gravity="bottom" />
        <FrameLayout
            android:id="@android:id/tabcontent"
            android:layout_width="fill_parent"
            android:layout_height="fill_parent"
            android:padding="5dp" >
            <!-- General Info Tab -->
            <LinearLayout
                android:id="@+id/general_tab"
                android:layout_width="fill_parent"
                android:layout_height="wrap_content"
                android:orientation="vertical" >
            </LinearLayout>
            <!-- Tool Tab -->
            <ListView
                android:id="@+id/list1"
                android:layout_width="match_parent"
                android:layout_height="0dp"
                android:layout_weight="1"
                android:drawSelectorOnTop="false" />
        </FrameLayout>
    </LinearLayout>
</TabHost>

activity for tabhost (edited to remove non-relevant code):

public class SetupDisplay extends TabActivity {
    private String[] tooldisplay = new String[20];
    private ListView mListView;
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.setupdetailmain);
        // Set up tabs
        TabHost tabHost = getTabHost();
        TabHost.TabSpec spec;
        spec = tabHost.newTabSpec("general").setIndicator("General")
                .setContent(R.id.general_tab);
        tabHost.addTab(spec);
        spec = tabHost.newTabSpec("tools").setIndicator("Tools")
                .setContent(R.id.list1);
        tabHost.addTab(spec);
        // Load data into tooldisplay[]
        // get view & set adapter
        mListView = (ListView)findViewById(R.id.list1);
        mListView.setAdapter(new ArrayAdapter<String>(this,
                android.R.layout.simple_list_item_1, tooldisplay));
    }
}
  • 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-29T19:04:51+00:00Added an answer on May 29, 2026 at 7:04 pm

    I found the source of my problem after much more googling. Posting an answer for anyone who might come later with the same issue.

    I was using the wrong contructor.

    Since I have more than a textview in the layout, I need to specify the layout AND the textview for the adapter (Note my code for the fix is a little different from originally posted as I switched to a custom list layout, but the issue was still there until I came upon the constructor fix).

        mListView.setAdapter(new ArrayAdapter<String>(this, 
                android.R.layout.simple_list_item_1, tooldisplay)); 
    

    should be:

        ListView mListView = (ListView)findViewById(R.id.list1);          
        mListView.setAdapter(new ArrayAdapter<String>(this,          
                R.layout.listlayout, R.id.ListItem1, tooldisplay));          
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

That's pretty much it. I'm using Nokogiri to scrape a web page what has
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I'm trying to create an if statement in PHP that prevents a single post
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I am reading a book about Javascript and jQuery and using one of the
I am trying to render a haml file in a javascript response like so:

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.