Android Two Fragments in Same Activity

Do the following:

  1. Change Fragment to FrameLayout in the main activity XML, for both.
  2. Change layout_width from fill_parent to match_parent, for both FrameLayout in the main XML file, (ones created in step 1).
  3. Change layout_height from fill_parent to wrap_content, for both FrameLayout in the main XML file, (ones created in step 1).
  4. Change FrameLayout to ListView in the List Fragment XML because it is a List.
  5. Change the id of this LisView to @android:id/list, because it is needed for the ListFragment.

Then let me know, Cheers.

Edit, also these:

  1. Change return inflater.inflate(R.layout.list_fragment, null); to return inflater.inflate(R.layout.list_fragment, container, false);.
  2. Change return inflater.inflate(R.layout.input_fragment, null); to return inflater.inflate(R.layout.input_fragment, container, false);

Edit:

Make your main activity XML file like this:

<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent" >

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

    <FrameLayout
        android:id="@+id/send_fragment"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:layout_alignParentBottom="true" />

</RelativeLayout>

I took out the android:name"..." because I don’t know what that is nor able to find out what it is, if you know what it does for sure, just add it back, should be okay.

Leave a Comment