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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T00:48:06+00:00 2026-06-01T00:48:06+00:00

I have a ViewPager with 3 fragments into it. Everything works fine with two

  • 0

I have a ViewPager with 3 fragments into it.
Everything works fine with two of them.
The problem is with the third pager This one is a TabHost, in which there is one fragment in each tab.
But I’ve read that it’s is not possible to put a Tabhost inside a Fragment. Nested fragments are forbidden.

Anyone has any idea of what can I do for resolving my problem?
Any alternatives?

  • 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-06-01T00:48:07+00:00Added an answer on June 1, 2026 at 12:48 am

    This is what i’ve done for resolving my problem.

    I’ve done one “custom” Tabhost”. I say “custom” because it is not a Tabhost, it seems to only.
    In one of my fragements inside the ViewPager, i’ve 4 images on top of the fragment. And the rest of the fragment is one FrameLayout.
    Each time i touch on the images, i replace the fragment which is in the frame for the respective fragemnt.

    I add some code:

    <LinearLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <LinearLayout 
    android:layout_width="match_parent" 
    android:layout_height="wrap_content"
    android:orientation="horizontal">
    <TableLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <TableRow >
    <LinearLayout android:id="@+id/button1"
    android:orientation="vertical"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:onClick="button1Click"
    >
    <ImageView android:id="@+id/iv1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/ic1"/>
    <TextView android:id="@+id/tv1"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="@string/text1"/>
    </LinearLayout>
    <LinearLayout android:id="@+id/button2"
    android:orientation="vertical"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:onClick="button2Click"
    >
    <ImageView android:id="@+id/iv2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/ic2"/>
    <TextView android:id="@+id/tv2"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="@string/text2"/>
    </LinearLayout>
    <LinearLayout android:id="@+id/button3"
    android:orientation="vertical"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:onClick="button3Click"
    >
    <ImageView android:id="@+id/iv3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/ic3"/>
    <TextView android:id="@+id/tv3"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="@string/text3"/>
    </LinearLayout>
    <LinearLayout android:id="@+id/button4"
    android:orientation="vertical"
    android:layout_width="0dip"
    android:layout_height="wrap_content"
    android:layout_weight="1"
    android:onClick="button4Click"
    >
    <ImageView android:id="@+id/iv4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:src="@drawable/ic4"/>
    <TextView android:id="@+id/tv4"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:gravity="center"
    android:text="@string/text4"/>
    </LinearLayout>
    
    </TableRow>
    </TableLayout>
    </LinearLayout>
    
    
    <FrameLayout android:id="@+id/layout_actual"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    
    </FrameLayout>
    
    </LinearLayout>
    

    In the FragmentActivity:

    public void boton1Click(View v){
        mFragmentInViewPager.changeFragment(BUTTON1);
    }
    
    public void boton2Click(View v){
        mFragmentInViewPager.changeFragment(BUTTON2);
    }
    
    public void boton3Click(View v){
        mFragmentInViewPager.changeFragment(BUTTON3);
    }
    public void boton4Click(View v){
        mFragmentInViewPager.changeFragment(BUTTON4);
    }
    

    And finally in the FragmentInViewPager (the one which contains the other 4 fragments)

    public void changeFragment(int fragmentId)
    {
    if(mCurrentFragmentId != fragmentId) {
    
    switch(fragmentId) {
    case BUTTON1:
    
        mFTransaction = mFManager.beginTransaction();
        mFTransaction.replace(R.id.layout_actual, mFragment1);
        mFTransaction.commit();
        mIv1.setImageResource(R.drawable.ic1_sel);
        mIv2.setImageResource(R.drawable.ic2);
        mIv3.setImageResource(R.drawable.ic3);
        mIv4.setImageResource(R.drawable.ic4);
        break;
    
    case BUTTON2:
        mFTransaction = mFManager.beginTransaction();
        mFTransaction.replace(R.id.layout_actual, mFragment2);
        mFTransaction.commit();
        mIv1.setImageResource(R.drawable.ic1);
        mIv2.setImageResource(R.drawable.ic2_sel);
        mIv3.setImageResource(R.drawable.ic3);
        mIv4.setImageResource(R.drawable.ic4);
        break;
    
    case BUTTON3:
        mFTransaction = mFManager.beginTransaction();
        mFTransaction.replace(R.id.layout_actual, mFragment3);
        mFTransaction.commit();
        mIv1.setImageResource(R.drawable.ic1);
        mIv2.setImageResource(R.drawable.ic2);
        mIv3.setImageResource(R.drawable.ic3_sel);
        mIv4.setImageResource(R.drawable.ic4);
        break;
    
    case BUTTON4:
        mFTransaction = mFManager.beginTransaction();
        mFTransaction.replace(R.id.layout_actual, mFragment4);
        mFTransaction.commit();
        mIv1.setImageResource(R.drawable.ic1);
        mIv2.setImageResource(R.drawable.ic2);
        mIv3.setImageResource(R.drawable.ic3);
        mIv4.setImageResource(R.drawable.ic4_sel);
        break;
    
    }
    
    mCurrentFragmentId = fragmentId;
    }
    
    }
    

    I hope of have explained myself well. If anyone needs more info, just tell me.

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

Sidebar

Related Questions

I have a ViewPager with multiple fragments. In one Fragment I play audio. When
I have implemented HorizontalListView inside ViewPager . ViewPager works fine but a child of
I have a problem with referencing my Fragments inside a ViewPager. I would like
I have two fragments in an Activity, In portrait mode the first one (ListFragment)
I have following problem: I have one activity in which I have two tabs
I need your help. I have one Activity with two fragments: one fragment with
I have a problem with ViewPager. It won't display any of my pre-definied fragments,
I have a ViewPager (extends FragmentPagerAdapter ) which holds two Fragments . What I
I have a FragmentActivity using a ViewPager to serve several fragments. Each is a
I have this loop method to display a ViewPager and I set an OnClickListener

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.