title: How to use Master/Detail Flow together with Tabs on Android
body: <p>I want to achieve the following layout to my android-application (upper layout for tablets, lower layout for smartphones) including the capability of swiping between the subitems:
  <img src="https://i.stack.imgur.com/fZBVp.png" alt="Application Layout on Tablet (upper) and on Smartphone (lower)"></p>
  
  <p>So I've created a Master/Detail-Flow Activity with Eclipse, which works fine. For the tabs I've taken a look at the Support-Library Samples (<code>&lt;sdk&gt;/extras/android/support/v4/samples/</code>), where a beautiful example is given (FragmentTabsPager.java), which extends the <code>FragmentActivity</code> class and makes use of <code>ViewPager</code> and the <code>TabHost</code>-Widget.</p>
  
  <p>My idea was to combine both examples into one application, so instead of using the TabPage as Activity, I want to use it as Fragment. On a smartphone this works nice, but on a tablet it works only once (meaning that when started for the first time, the content is loaded correctly, but as soon as I click on another item in the left list, no more content is loaded). To be more precise: The tabs are loaded and have the correct label, but the content that should be shown in the content-area of the tab is not there, although you can swipe between the tabs, as if the content was there.</p>
  
  <p>My questions are:</p>
  
  <ul>
  <li>Is this approach meaningful (to combine master/detail with tabs)? Or should I use a completely different approach?</li>
  <li>Do you know how to fix the issue, that the content is not loading properly?</li>
  </ul>
  
  <p>To make it easier to see, I've created a demo-app from scratch with exactly this idea, which can be downloaded from <a href="https://github.com/apacha/MasterDetail_And_Tabs" rel="nofollow noreferrer">https://github.com/apacha/MasterDetail_And_Tabs</a>.</p>
  
  <p>Related posts on Stackoverflow that didn't fix the issue: <a href="https://stackoverflow.com/questions/7263291/viewpager-pageradapter-not-updating-the-view">ViewPager PagerAdapter not updating the View</a>,</p>
  
  <p><strong>Edit1</strong>: I've learned about <a href="http://developer.android.com/reference/android/support/v4/app/FragmentTabHost.html" rel="nofollow noreferrer">http://developer.android.com/reference/android/support/v4/app/FragmentTabHost.html</a> and found <a href="https://stackoverflow.com/questions/13686282/android-fragmenttabhost-not-fully-baked-yet">Android FragmentTabHost - Not fully baked yet?</a>. With these hints I managed to get it almost running, but now I can chose between a working version which does not provide swipe-support (if I add the Tabs directly to the tabHost:</p>
  
  <pre><code>FragmentTabHost mTabHost = new FragmentTabHost();
  // Add directly to tab-host
  mTabHost.addTab(mTabHost.newTabSpec("simple1").setIndicator("Simple1"), CountingFragment.class, b);
  </code></pre>
  
  <p>of a buggy swipe-implementation if I add it and use the FragmentPagerAdapter</p>
  
  <pre><code>FragmentTabHost mTabHost = new FragmentTabHost();
  ViewPager mViewPager = (ViewPager) rootView.findViewById(R.id.pager);
  TabsAdapter mTabsAdapter = new TabsAdapter(getActivity(), mTabHost, mViewPager);
  // Add to tab-host-adapter
  mTabsAdapter.addTab(mTabHost.newTabSpec("simple1").setIndicator("Simple1"), CountingFragment.class, b);
  </code></pre>
  
  <p>I've commited all changes to the repository mentioned above.</p>