Java 我想用导航抽屉添加其他内容

Java 我想用导航抽屉添加其他内容,java,android,android-drawer,Java,Android,Android Drawer,我是android新手。 我已经使用列表视图(使用基本适配器的自定义列表视图)创建了一个抽屉布局。 这是我的代码活动_main.xml。当我运行应用程序时,我看到一个空屏幕。Listview工作正常。但我只需要在屏幕上添加其他内容,如mapview或其他任何内容。当导航菜单打开时,我想让内容移动。如何在下面的代码中添加列表视图以外的内容 <android.support.v4.widget.DrawerLayout xmlns:android="http://schemas.andro

我是android新手。 我已经使用列表视图(使用基本适配器的自定义列表视图)创建了一个抽屉布局。 这是我的代码活动_main.xml。当我运行应用程序时,我看到一个空屏幕。Listview工作正常。但我只需要在屏幕上添加其他内容,如mapview或其他任何内容。当导航菜单打开时,我想让内容移动。如何在下面的代码中添加列表视图以外的内容

  <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>


FrameLayout
是保存主要内容的布局。创建一个片段及其布局,然后在
main活动中
将片段添加到
FrameLayout
中,如下所示

MyFragment fragment=newmyfragment();
FragmentTransaction ft=getSupportFragmentManager().beginTransaction();
ft.add(R.id.mainContent,fragment,“fragment”).commit()`;

MyFragment是扩展Fragment的独立类吗?我尝试为Fragment创建独立类和布局,但发现这些错误类型不匹配:无法从android.support.v4.app.FragmentTransaction转换为android.app.FragmentTransaction您的片段应该扩展android.support.v4.app.Fragment而不是android.app.Fragment。
 MyFragment fragment = new MyFragment();
 FragmentTransaction ft = getSupportFragmentManager().beginTransaction();
 ft.add(R.id.mainContent, fragment, "fragment").commit()`;