1

I want to show two fragments (one listfragment and other is details fragment) in the main contentview of navigation drawer like below:

enter image description here

But AFAIK, there can be only one view in the main contentview of drawerLayout. So how can achieve this?

Kaidul
  • 15,409
  • 15
  • 81
  • 150

1 Answers1

3

Anything you put inside the FrameLayout will be in the main content view.

You can put whatever you want (including multiple Fragments) inside this FrameLayout:

<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/drawer_layout"
    android:layout_width="match_parent"
    android:layout_height="match_parent">
    <!-- The main content view -->
    <FrameLayout
        android:id="@+id/content_frame"
        android:layout_width="match_parent"
        android:layout_height="match_parent">

        <!-- YOUR CONTENT HERE -->
        <!-- Could be layout with multiple views or fragments -->            

    </FrameLayout


    <!-- The navigation drawer -->
    <ListView android:id="@+id/left_drawer"
        android:layout_width="240dp"
        android:layout_height="match_parent"
        android:layout_gravity="start"
        android:choiceMode="singleChoice"
        android:divider="@android:color/transparent"
        android:dividerHeight="0dp"
        android:background="#111"/>
</android.support.v4.widget.DrawerLayout>
Booger
  • 18,579
  • 7
  • 55
  • 72
  • Thanks for your answer. Actually I need to put three `listFragment`s into the main contentview. So should I put three `FrameLayout`s inside the main `FrameLayout` for these purpose? – Kaidul Jul 13 '13 at 18:17
  • 1
    No, just your 3 listFragments by themselves. I think you may have other issues (mainly dealing with scrolling) with 3 listviews inside one parent. Also, you may want to put all 3 fragments inside a single parent (like a LinearLayout), to provide more control. Bottom line, put whatever you want, inside the current FrameLayout. – Booger Jul 13 '13 at 19:56
  • Yes, I need to be able the listview to be scrolled inside the parent. SO is it sufficient to put the three listfragment inside the frameLayout? or why I need an extra LinearLayout to wrap them? – Kaidul Jul 13 '13 at 20:11