Home » Android » Android TabHost inside Fragment

Android TabHost inside Fragment

Posted by: admin June 15, 2020 Leave a comment

Questions:

I am working on an Android App and I have used android FragmentPager tabs example from developer.android.com), this example uses fragments for tabs contents, Now I want to place a tabHost inside one of those fragments, I have tried my best but the second tab hosts are not showing the content, I can see tab headers but no content, I am trying to use Intents as TabContent. I don’t think I have any relevant code to post here, but If you need I can post it here.

The hierarchy is: FragmentActivity->TabHost->Fragments->TabHost->(Intent or Fragment, this is the problem area)

Any Suggestion would be appreciated.

How to&Answers:

Have you seen this? I’ve referenced it a few times, should help you out.

http://thepseudocoder.wordpress.com/2011/10/04/android-tabs-the-fragment-way/

Answer:

Now you can use FragmentTabHost

This can also be used inside of a fragment through fragment nesting

http://developer.android.com/reference/android/support/v4/app/FragmentTabHost.html

Answer:

I face the same problem we. We cannot open a fragment or activity in another tab.(We an but it will open in the same tab). So i am use to the below code to change the tab.

 MainActivity.tabHost.setCurrentTab(tabIndex);

Its open the tab with the main tab page.