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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:21:21+00:00 2026-05-25T03:21:21+00:00

Hi I have a problem with my tabhost and I don’t really understand why.

  • 0

Hi
I have a problem with my tabhost and I don’t really understand why.
My tab host contains 4 listviews and shows a list in each tab. Sometimes when I change the tab (click on new tab) the content doesn’t change or it freezes. I have tried it on several devices and the problem is still there

Here is my code:

public class TabHostActivity extends TabActivity implements OnTabChangeListener {

    private TabHost mTabHost;
    private Resources mResources;
    private SharedPreferences prefs;
    private ListView lv1;
    private ListView lv2;
    private ListView lv3;
    private ListView lv4;
    private String servicio = "teatre"; // por ahora luego varia segun los
                                        // eventos
    private String servicio2 = "expos";
    private static final String Tab_title1 = "Agenda";
    private static final String Tab_title3 = "Teatre";
    private static final String Tab_title4 = "Exposicions";
    private static final String Tab_title2 = "Cinema";
    private EventsList eventsL;
    private ArrayList<Event> events;
    private EventAdapterAprop mAdapter;
    private EventAdapterAprop mAdapter2;
    private EventAdapterAprop mAdapter3;
    private EventAdapterAprop mAdapter4;
    private EventsList eventsL3;
    private EventsList eventsL4;
    private ArrayList<Event> events3;
    private ArrayList<Event> events4;
    private EventsList eventsL2;
    private ArrayList<Event> events2;

    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.tabhost);

        mTabHost = getTabHost();
        lv1 = (ListView) findViewById(R.id.list1);

        lv2 = (ListView) findViewById(R.id.list2);
        lv3 = (ListView) findViewById(R.id.list3);
        lv4 = (ListView) findViewById(R.id.list4);

        Bundle b = getIntent().getExtras();

        //agenda
        try{
        eventsL = b.getParcelable("events");
        events = new ArrayList<Event>();

        for (int i = 0; i < eventsL.size(); i++) {
            events.add(eventsL.get(i));
        }


            mAdapter = new EventAdapterAprop(this, events);
        } catch (Exception ex) {
            ex.printStackTrace();
            mAdapter = new EventAdapterAprop(this, crearVacio());
        }
        // teatro

        try{
        eventsL3 = b.getParcelable("events3");
        events3 = new ArrayList<Event>();

        for (int i = 0; i < eventsL3.size(); i++) {
            events3.add(eventsL3.get(i));
        }


            mAdapter3 = new EventAdapterAprop(this, events3);
        } catch(Exception ex) {
            mAdapter3 = new EventAdapterAprop(this, crearVacio());
            ex.printStackTrace();
        }


        // expos
        try{
        eventsL4 = b.getParcelable("events4");
        events4 = new ArrayList<Event>();

        for (int i = 0; i < eventsL4.size(); i++) {
            events4.add(eventsL4.get(i));
        }

            mAdapter4 = new EventAdapterAprop(this, events4);
        } catch(Exception ex){
            mAdapter4 = new EventAdapterAprop(this, crearVacio());
            ex.printStackTrace();
        }

        // cine
        try{
        eventsL2 = b.getParcelable("events2");
        events2 = new ArrayList<Event>();

        for (int i = 0; i < eventsL2.size(); i++) {
            events2.add(eventsL2.get(i));
        }


            mAdapter2 = new EventAdapterAprop(this, events2);
        } catch(Exception ex) {
            mAdapter2 = new EventAdapterAprop(this, crearVacio());
            ex.printStackTrace();
        }

        //mAdapter2=new EventAdapterAprop(this, crearVacio());

        lv1.setAdapter(mAdapter);
        lv1.setTextFilterEnabled(true);
        lv1.computeScroll();

        lv2.setAdapter(mAdapter2);
        lv2.setTextFilterEnabled(true);
        lv2.computeScroll();

        lv3.setAdapter(mAdapter3);
        lv3.setTextFilterEnabled(true);
        lv3.computeScroll();

        lv4.setAdapter(mAdapter4);
        lv4.setTextFilterEnabled(true);
        lv4.computeScroll();

        mTabHost.addTab(mTabHost.newTabSpec(Tab_title1)
                .setIndicator(Tab_title1).setContent(new TabContentFactory() {
                    public View createTabContent(String arg0) {
                        return lv1;
                    }
                }));
        mTabHost.addTab(mTabHost.newTabSpec(Tab_title2)
                .setIndicator(Tab_title2).setContent(new TabContentFactory() {
                    public View createTabContent(String arg0) {
                        return lv2;
                    }
                }));

        mTabHost.addTab(mTabHost.newTabSpec(Tab_title3)
                .setIndicator(Tab_title3).setContent(new TabContentFactory() {
                    public View createTabContent(String arg0) {
                        return lv3;
                    }
                }));
        mTabHost.addTab(mTabHost.newTabSpec(Tab_title4)
                .setIndicator(Tab_title4).setContent(new TabContentFactory() {
                    public View createTabContent(String arg0) {
                        return lv4;
                    }
                }));
    }

    public ArrayList<Event> crearVacio() {
        ArrayList<Event> arrayList = new ArrayList<Event>();
        Event e = new Event();
        e.setTitle("Cap esdeveniment correspon a la seva recerca");
        e.setDates("");
        e.setTimes("");
        e.setVenue("");
        arrayList.add(e);
        return arrayList;
    }

    @Override
    public void onTabChanged(String tabId) {
        // TODO Auto-generated method stub

    }

    }

and the 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" 
    xmlns:android1="http://schemas.android.com/apk/res/android">
    <LinearLayout android:orientation="vertical"
        android:layout_width="fill_parent" android:layout_height="fill_parent"
        android:background="@drawable/fonsbutxacadroid2">
        <TabWidget android:id="@android:id/tabs"
            android:layout_width="fill_parent" 
            android:layout_height="wrap_content" 
            android1:background="@color/amarillo1"/>
        <FrameLayout android:id="@android:id/tabcontent"
            android:layout_width="fill_parent" android:layout_height="fill_parent">
            <ListView android:id="@+id/list1" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:layout_weight="1" 
                >
            </ListView>
            <ListView android:id="@+id/list2" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:layout_weight="1"
                >
            </ListView>
            <ListView android:id="@+id/list3" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:layout_weight="1"
                >
            </ListView>
            <ListView android:id="@+id/list4" android:layout_width="fill_parent"
                android:layout_height="wrap_content" android:layout_weight="1"
                >
            </ListView>
        </FrameLayout>
    </LinearLayout>
</TabHost>

What is wrong?

Thanks in advance.

  • 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-25T03:21:21+00:00Added an answer on May 25, 2026 at 3:21 am

    Making each tab one separate activity solved the problem

    layout example:

    <?xml version="1.0" encoding="utf-8"?>
    <TabHost xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="fill_parent"
    xmlns:android1="http://schemas.android.com/apk/res/android" 
    android1:id="@+id/@android:id/tabhost" android1: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"
            >           
        </FrameLayout>
    </LinearLayout>
    

    The tabhost class:

    public class AllActivitiesTabs extends TabActivity {
    
    private static final String Tab_title = "Nueva";
    private TabHost mTabHost;
    private TextView txtTabInfo;
    
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
    
    
    mTabHost = getTabHost();
    
    TabSpec spec;
    //to add one tab activity       
    txtTabInfo = new TextView(getApplicationContext());
    txtTabInfo.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,         
    LayoutParams.WRAP_CONTENT));
    txtTabInfo.setBackgroundDrawable(getResources().getDrawable(
                R.drawable.tab_incidencia));
    Intent intent = new Intent();
    intent.setClass(this, ListActivityClass.class);
    spec = mTabHost.newTabSpec(Tab_title).setIndicator(txtTabInfo)
                .setContent(intent);
    mTabHost.addTab(spec);
    
    //do the same for other activities
    //your activities can be lists or something else:
    
    
    txtTabInfo2 = new TextView(getApplicationContext());
    txtTabInfo2.setBackgroundDrawable(getResources().getDrawable(
                R.drawable.tab_solucions));
    txtTabInfo2.setLayoutParams(new LayoutParams(LayoutParams.WRAP_CONTENT,     
    LayoutParams.WRAP_CONTENT));
    intent = new Intent();
    intent.setClass(this, FirstGroup.class);
    
    spec = mTabHost.newTabSpec(Tab_title2).setIndicator(txtTabInfo2)
                .setContent(intent);
    mTabHost.addTab(spec);
    }
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here's my problem: I've have an application with tabs. in each tab I have
I have a tabhost with some tabs, and each tab have implemented the method
I need to have a TabHost consisting of two tabs where each tab represented
I have created a tab host. Now when I set the background of each
I have created four tabs using tabhost, and placed four listviews in each like
I want to use TabHost, but my app has stopped unexpectedly. I don't really
I have added 4 activities to a tabhost widget. These work fine. The problem
Currently I have a TabHost implemented with 3 tabs each containing a separate activity.
I have problem with initializing TabHost. I need to have in View several Tabs
I have tabhost with 4 tabs. If I (for example) open tab #3, start

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.