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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T05:52:22+00:00 2026-05-25T05:52:22+00:00

I have done TABS in my app using TabHost. one of the tabs has

  • 0

I have done TABS in my app using TabHost.
one of the tabs has two buttons in it(“button”,”anotherButton”)

After I run my app I can see both tabs, but when I press on them nothing happens(they aren’t even “clickable” when I press them.) And moreover, they don’t respond to any listeners which I add to them.

Some code:

main.xml:

<?xml version="1.0" encoding="utf-8"?>
<TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+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">
        <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">
            <AnalogClock android:id="@+id/tab1" android:layout_width="fill_parent"
                android:layout_height="fill_parent" android:layout_centerHorizontal="true" />

            <LinearLayout android:id="@+id/linearbuttonsview"
                android:orientation="vertical" android:layout_width="fill_parent"
                android:layout_height="fill_parent">


----pay attention here I decalred tab with two buttons !!! -----------------


                <Button android:id="@+id/button" android:layout_width="wrap_content"
                    android:onClick="onSemiButtonClick" android:layout_height="wrap_content" android:text="A semi-random button" />

                <Button android:id="@+id/anotherButton" android:layout_width="wrap_content"
                    android:layout_height="wrap_content" android:text="A semi-semi-random button"
                    android:scrollY="400px" />


            </LinearLayout>


            <ListView android:id="@+id/tablist" android:layout_width="fill_parent"

                android:layout_height="fill_parent" />




        </FrameLayout>
    </LinearLayout>
</TabHost>

This is my code:

public class TabDemo extends Activity
{
    private ListView ls1;
    private Button semiButton;

    @Override
    public void onCreate(Bundle icicle)
    {
        super.onCreate(icicle);
        setContentView(R.layout.main);
        ls1 = new ListView(TabDemo.this);
        TabHost tabs = (TabHost) findViewById(R.id.tabhost);
        semiButton = (Button) findViewById(R.id.button);
        semiButton.setOnClickListener(new OnClickListener()
        {

            public void onClick(View v)
            {

                int z = 0;
                z++;
            }

        });

        tabs.setup();

        // tab1
        TabSpec spec = tabs.newTabSpec("tag1");
        spec.setContent(R.id.tab1);
        spec.setIndicator("Clock");
        tabs.addTab(spec);

        // tab2
        spec = tabs.newTabSpec("tag2");
        spec.setContent(R.id.linearbuttonsview);
        spec.setIndicator("Button");
        tabs.addTab(spec);

        // tab3
        spec = tabs.newTabSpec("tag3");
        spec.setContent(new TabHost.TabContentFactory()
        {

            // we create a list view and give it as a reference to the the
            // content
            public View createTabContent(String tag)

            {

                ArrayAdapter<String> adapter = new ArrayAdapter<String>(
                        TabDemo.this, android.R.layout.simple_list_item_1,
                        new String[]
                        { "item1", "item2", "item3" });

                ls1.setAdapter(adapter);

                return ls1;

            }

        });
        spec.setIndicator("List");
        tabs.addTab(spec);
    }
}
  • 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-25T05:52:23+00:00Added an answer on May 25, 2026 at 5:52 am

    some change in your code (create each tab with different activity)

    public class TabBarExample extends TabActivity {
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.tab);
    
            TabHost tabHost = (TabHost)findViewById(android.R.id.tabhost);
    
            TabSpec firstTabSpec = tabHost.newTabSpec("tid1");
            TabSpec secondTabSpec = tabHost.newTabSpec("tid1");
    
            firstTabSpec.setIndicator("First Tab").setContent(new Intent(this,FirstTab.class));
            secondTabSpec.setIndicator("Second Tab").setContent(new Intent(this,SecondTab.class));
    
            tabHost.addTab(firstTabSpec);
            tabHost.addTab(secondTabSpec);
    
        }
    }
    

    FirstTab.java

    public class FirstTab extends Activity {
    
        Button bt;
    
        @Override
        public void onCreate(Bundle savedInstanceState) {
            super.onCreate(savedInstanceState);
            setContentView(R.layout.tabs1);
    
            bt = (Button) findViewById(R.id.button1);
    
            bt.setOnClickListener(new OnClickListener() {
    
                @Override
                public void onClick(View v) {
    
                    Toast.makeText(FirstTab.this, "it's works", 2000).show();
                }
            });
        }
    }
    

    tab.xml

    <TabHost android:layout_width="fill_parent"
        android:layout_height="fill_parent" xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@android:id/tabhost">
        <LinearLayout android:id="@+id/LinearLayout01"
            android:orientation="vertical" android:layout_height="fill_parent"
            android:layout_width="fill_parent">
            <TabWidget android:id="@android:id/tabs"
                android:layout_height="wrap_content" android:layout_width="fill_parent"></TabWidget>
            <FrameLayout android:id="@android:id/tabcontent"
                android:layout_height="fill_parent" android:layout_width="fill_parent"></FrameLayout>
        </LinearLayout>
    
    </TabHost>
    

    tab1.xml

    <LinearLayout android:id="@+id/LinearLayout01"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        xmlns:android="http://schemas.android.com/apk/res/android">
        <Button android:text="Button" android:id="@+id/button1"
            android:layout_width="wrap_content" android:layout_height="wrap_content"></Button>
    </LinearLayout>
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an app with one main TabBarController containing two tabs that control two
I have done one program that allow user can listen to the music via
From what I have done in past(before using knockoutjs) I would call the tabs()
I have an app with a tab bar controller (2 tabs). In one tab
I have done strace on my multi-threaded c++ application running on linux after couple
I have done small project in c++, the IDE I am using is Visual
I am building an application that has the functionality like 3 tabs created using
I have a form with multiple tabs. Each tab has its own <form> ,
my app starts with a tab bar controller which have 5 tabs. At start
In my app I have four tabs in the bottom of my main screen.

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.