-1

I am new to android. I have created a drawer layout using list view (custom list view using base adapter). this is my code activity_main.xml. When i run the application i see an empty screen. Listview is working properly. But i just need to add another content in the screen, like mapview or anything else. And i want that content to move when the navigation menu is opened. How to add content other than list view in the below code?

  <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android"
 android:id="@+id/drawerLayout"
 android:layout_width="match_parent"
 android:layout_height="match_parent">

<FrameLayout 
    android:id="@+id/mainContent"
    android:layout_width="match_parent"
    android:layout_height="match_parent">

 </FrameLayout>

<ListView 
    android:id="@+id/drawerList"
    android:background="#CECECE"
    android:divider="@null"
    android:layout_width="240dp"
    android:layout_height="match_parent"
    android:layout_gravity="left"></ListView>

Varuni N R
  • 802
  • 3
  • 11
  • 31

1 Answers1

0

FrameLayout is the one that holds your main content. Create a fragment and its layout, then on your MainActivity you add the fragment to the FrameLayout like this.

 MyFragment fragment = new MyFragment();
 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
 ft.add(R.id.mainContent, fragment, "fragment").commit()`; 
Aroniez
  • 99
  • 2
  • 11
  • Is MyFragment is a seperate class which extends Fragment?? – Varuni N R Jul 17 '15 at 12:07
  • I tried creating seperate class and layout for fragment and i am getting these errors Type mismatch: cannot convert from android.support.v4.app.FragmentTransaction to android.app.FragmentTransaction – Varuni N R Jul 17 '15 at 12:08
  • your fragment should extend android.support.v4.app.Fragment instead of android.app.Fragment. – Aroniez Jul 17 '15 at 12:40