title: Accessing parent Fragment layout from child Fragment
body: <p>Good day to all. I can't figure out how to access parent Fragment layout from child Fragment. Let's say I have main activity with tabs defined in ActionBar. Each Tab is Fragment. Now in one of those tabs I want to use tabs again (sticked to bottom this time). I'm able to create needed layout using classic TabHost. Each of these sub-tabs will be operated by same Fragment class - literally it should be plain ListView with almost same data from database, it will differ by one field only (full list, "visited" items and "not visited").</p>
  
  <p>So here's my parent PlanFragment, which is placed on of tabs of main Activity. It has TabHost and populates 3 Tabs using PlanListFragment:</p>
  
  <pre><code>public class PlanFragment extends Fragment implements OnTabChangeListener {
  
      protected static final String TAG = "PlanFragment";
  
      public static final String TAB_FULL = "full";
      public static final String TAB_VISITED = "visited";
      public static final String TAB_NOT_VISITED = "not_visited";
  
      private View mRoot;
      private TabHost mTabHost;
      private int mCurrentTab;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          mRoot = inflater.inflate(R.layout.fragment_plan, container, false);
          mTabHost = (TabHost) mRoot.findViewById(android.R.id.tabhost);
          setupTabs();
          return mRoot;
      }
  
      @Override
      public void onActivityCreated(Bundle savedInstanceState) {
          super.onActivityCreated(savedInstanceState);
          setRetainInstance(true);
  
          mTabHost.setOnTabChangedListener(this);
          mTabHost.setCurrentTab(mCurrentTab);
          updateTab(TAB_FULL, R.id.tab_plan_full);
      }
  
      private void setupTabs() {
          mTabHost.setup();
          mTabHost.addTab(newTab(TAB_FULL, R.string.label_tab_plan_full,
                  R.id.tab_plan_full));
          mTabHost.addTab(newTab(TAB_VISITED,
                  R.string.label_tab_plan_visited, R.id.tab_plan_visited));
          mTabHost.addTab(newTab(TAB_NOT_VISITED,
                  R.string.label_tab_plan_unvisited, R.id.tab_plan_not_visited));
      }
  
      private TabSpec newTab(String tag, int labelId, int tabContentId) {
          TabSpec tabSpec = mTabHost.newTabSpec(tag);
          tabSpec.setIndicator(getActivity().getString(labelId));
          tabSpec.setContent(tabContentId);
          return tabSpec;
      }
  
      @Override
      public void onTabChanged(String tabId) {
          if(TAB_FULL.equals(tabId)) {
              updateTab(tabId, R.id.tab_plan_full);
              mCurrentTab = 0;
              return;
          }
          if(TAB_VISITED.equals(tabId)) {
              updateTab(tabId, R.id.tab_plan_visited);
              mCurrentTab = 1;
              return;
          }
          if(TAB_NOT_VISITED.equals(tabId)) {
              updateTab(tabId, R.id.tab_plan_not_visited);
              mCurrentTab = 2;
              return;
          }
      }
  
  
      private void updateTab(String tabId, int placeholder) {
          FragmentManager fm = getFragmentManager();
          if (fm.findFragmentByTag(tabId) == null) {
              PlanListFragment plan = new PlanListFragment();
              Bundle params = new Bundle();
              params.putString(PlanListFragment.TAG, tabId);
              plan.setArguments(params);
              fm.beginTransaction()
                      .replace(placeholder, plan, tabId)
                      .commit();
          }
      }
  
  }
  </code></pre>
  
  <p>Here's layout with TabHost:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;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" &gt;
  
      &lt;LinearLayout
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:orientation="vertical"
          android:padding="5dp" &gt;
  
          &lt;FrameLayout
              android:id="@android:id/tabcontent"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_weight="1"
              android:padding="5dp" &gt;
  
              &lt;FrameLayout
                  android:id="@+id/tab_plan_full"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent" &gt;
  
                  &lt;include layout="@layout/plan_list" /&gt;
              &lt;/FrameLayout&gt;
  
              &lt;FrameLayout
                  android:id="@+id/tab_plan_visited"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent" &gt;
  
                  &lt;include layout="@layout/plan_list" /&gt;
              &lt;/FrameLayout&gt;
  
              &lt;FrameLayout
                  android:id="@+id/tab_plan_not_visited"
                  android:layout_width="fill_parent"
                  android:layout_height="fill_parent" &gt;
  
                  &lt;include layout="@layout/plan_list" /&gt;
              &lt;/FrameLayout&gt;
          &lt;/FrameLayout&gt;
  
          &lt;TabWidget
              android:id="@android:id/tabs"
              android:layout_width="fill_parent"
              android:layout_height="wrap_content"
              android:layout_marginBottom="-4dp"
              android:layout_weight="0" /&gt;
      &lt;/LinearLayout&gt;
  
  &lt;/TabHost&gt;
  </code></pre>
  
  <p>plan_list.xml included on each tab:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:id="@+id/LinearLayout1"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;TextView
          android:id="@+id/textView1"
          android:layout_width="wrap_content"
          android:layout_height="wrap_content"
          android:text="Large Text"
          android:textAppearance="?android:attr/textAppearanceLarge" /&gt;
  
      &lt;ListView
          android:id="@+id/listView1"
          android:layout_width="match_parent"
          android:layout_height="wrap_content" &gt;
      &lt;/ListView&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p>And finally PlanListFragment in which I plan to setup CursorAdapter for database based on parameter passed from parent Fragment. How do I access ListView here?</p>
  
  <pre><code>public class PlanListFragment extends ListFragment {
  
      protected static final String TAG = "PlanListFragment";
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          Bundle params = getArguments();
          Log.d(TAG, params.getString(TAG));
          return null;
      }
  
  }
  </code></pre>