Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android Fragment Not Replacing Properly

I am trying to build an app for 3.0 using fragments. On the left side of the application there is a static fragment, and on the right side there is a dynamic one. Each of my fragments in the dynamic portion have a title. Whenever I go to replace the initial fragment, The title of the first is still shown above the title of the first. Successive replacements replace the lower portion but the initial title is still shown (sorry I cannot post images yet).

Best I can do for image:

Initial Header

New Header

Content(displays fine)

main.xml:

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:orientation="horizontal" >
    <fragment
        android:id="@+id/static_fragment"
        android:name="ruleout.android.History_Fragment"
        android:layout_width="500dp"
        android:layout_height="match_parent" />
    <fragment
        android:id="@+id/dynamic_fragment"
        android:name="ruleout.android.New_Screen_Fragment"
        android:layout_width="fill_parent"
        android:layout_height="match_parent" />
</LinearLayout>

Partial MainActivity used to change fragments

private void open(Fragment toShow)
{
    FragmentTransaction fragmentTransaction = FragMag.beginTransaction();
    fragmentTransaction.replace(R.id.dynamic_fragment, toShow);
    fragmentTransaction.addToBackStack(null);
    fragmentTransaction.commit();
}

Please let me know if you need any additional information and thanks in advance for your help.

like image 607
cren90 Avatar asked Mar 11 '26 23:03

cren90


1 Answers

If you want to dynamically change fragments, you can't declare them in your layout. The Fragment documentation has an example of doing just what I think you are describing, where a layout has a static fragment declared in it along with a FrameLayout for holding a Fragment that will be dynamically added and replaced.

like image 123
hackbod Avatar answered Mar 14 '26 12:03

hackbod



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!