-1

Actually I am developing an app which has navigation drawer ,I want to use fragment instead of separate activities . I want to how it can be done? Thanks In advance.

  • Add a frame layout to your navigationdrawer activity and make fragments and then use fragment manager to show it .... – Sahil Sep 11 '17 at 03:12
  • please refer the [enter link description here](https://stackoverflow.com/questions/42623912/get-fragment-from-backstack-for-second-time/42624124#42624124) – Sushil Dubey Sep 11 '17 at 03:13
  • @SushilDubey actually I created one fragment and it's layout file , I included it in it in my main activity's layout file , and created fragment Manager , fragment transaction begin .. Etc But content in fragment is being shown directly irrespective of any action . – Himamsh Kilubatla Sep 11 '17 at 03:25
  • Add the fragment only after you perform your action – Ayush Khare Sep 11 '17 at 03:32
  • @AyushKhare Yeah I have done the same thing , when user selects one of the options in navigation drawer ,this fragment should be called. – Himamsh Kilubatla Sep 11 '17 at 03:45
  • Then post some code please, and you don't need to include your fragment layout in your activity layout! You need a frame layout and you will place you fragment using fragment transaction – Ayush Khare Sep 11 '17 at 03:46
  • I suggest you read the tutorial on http://developer.android.com. – Code-Apprentice Sep 11 '17 at 04:54

1 Answers1

0

Check this sample code.Hope this helps you.

<?xml version="1.0" encoding="utf-8"?>
<android.support.v4.widget.DrawerLayout
    xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:fitsSystemWindows="true"
    tools:openDrawer="start">

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="vertical">

    <include layout="@layout/toolbar_layout">
        <!--The Toolbar Layout if you have toolbar-->
    </include>

    <FrameLayout
        android:id="@+id/base_container"
        android:layout_width="match_parent"
        android:layout_height="0dp"
        android:layout_weight="1">

        <!--The layout where you need to add different
            fragments on click of nabigation items-->

    </FrameLayout>

</LinearLayout>

<LinearLayout
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:layout_gravity="start"
    android:orientation="vertical">

 <!--The navigation drawer items-->
</LinearLayout>

Sharath kumar
  • 4,064
  • 1
  • 14
  • 20