FragmentTransaction.replace() not working

后端 未结 5 1765
星月不相逢
星月不相逢 2021-01-07 22:37

I have a ListFragment displaying a list of items that created by the user. I have a ListView with it\'s id set to \"@android:id/list\" and a

相关标签:
5条回答
  • 2021-01-07 22:45

    Another solution is use LinearLayout Instead of fragment

     <Fragment
            android:name="path/to.package.MyClass"
            android:id="@+id/fragmentContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="100dp"
             />
    

    USE it like this

     <LinearLayout
            android:name="path/to.package.MyClass"
            android:id="@+id/fragmentContainer"
            android:layout_width="match_parent"
            android:layout_height="wrap_content"
            android:layout_marginBottom="100dp"
             />
    
    0 讨论(0)
  • 2021-01-07 22:46

    An other problem that solved the issue in my case were diffentent API imports.

    Make sure, that you use "support.v4" or the "original" implementations from API 11 and do not mix them. (this can happen, in my case: TransactionManager was v4 and the Activity an older version, or the other way around)

    0 讨论(0)
  • 2021-01-07 22:48

    I had a similar problem.

    According to this when you need to add Fragments programmatically, you should add them to an existing ViewGroup.

    So I removed the Fragment from the xml and used FrameLayout component in the replace() method.

    You can also have a look here.

    Hope this helps.

    0 讨论(0)
  • 2021-01-07 22:59

    Give a background color to the main layout of the childFragment.

    Like android:background="#FFFFFF"

    This worked for me!!!!

    0 讨论(0)
  • 2021-01-07 23:03

    I solved changing the RelativeLayout for a LinearLayout... Hope it helps!

    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:orientation="vertical" android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:background="@color/windowBackground">
    
    
        <FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
            android:id="@+id/fragment_container"
            android:layout_width="match_parent"
            android:layout_height="match_parent" />
    
    
    </LinearLayout>
    
    0 讨论(0)
提交回复
热议问题