Update snippet with new Android snippet

I have a layout

    <?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android" android:orientation="vertical" 
    android:layout_width="fill_parent" android:layout_height="wrap_content" >
    <LinearLayout android:id="@+id/linearLayout1" android:layout_height="wrap_content" android:orientation="horizontal" android:layout_width="wrap_content">
        <LinearLayout android:id="@+id/linearLayout13" android:layout_height="wrap_content" android:paddingRight="70dp" android:orientation="vertical" android:paddingLeft="70dp" android:layout_width="wrap_content">
            <ImageView android:id="@+id/baby_icon" android:layout_height="wrap_content" android:src="@drawable/baby" android:clickable="true" android:layout_width="wrap_content"></ImageView>
        </LinearLayout>
    </LinearLayout>
    <fragment
        android:name="com.nicu.health.FragAFragment"
        android:layout_width="match_parent"
        android:layout_height="match_parent"
        android:id="@+id/yellow_cardlist_fragment"
        android:layout_weight="1"
        >
    </fragment>
</LinearLayout>

At startup, this shows the correct fragment (FragAFragment). Now click on the button for baby_icon. I am trying to delete the current fragment and add a new one (FragBFragment), which has a completely different format.

Although I see that the method is being called onCreateView, and it returns a non-zero view, the user interface on the screen of the new fragment is not updated. I am using the code below to update a fragment.

                        Fragment baby = FragBFragment.newInstance(1);
                    FragmentTransaction ft = getFragmentManager().beginTransaction();
//                  ft.remove(getFragmentManager().findFragmentById(R.id.yellow_cardlist_fragment));
//                  ft.add(R.id.yellow_cardlist_fragment, baby);
                    ft.replace(R.id.yellow_cardlist_fragment, baby);
                    ft.addToBackStack(null);
                    Log.i(TAG, "Code for commit = "+ft.commit());

I tried all the remove, replace, and add combinations to get the fragment working, but in vain!

I also tried with code like

<fragment
    android:name="com.nicu.health.FragBFragment"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:id="@+id/yellow_cardlist_fragment"
    android:layout_weight="1"
    >

and this works to show the second fragment at startup !!!!

Help will be reeally appreicated.

Thank,

+3
source share
2

Android:

onclick. ft.replace, .

+7

, : ft.commit();

:

, u Activity AB, A B.

3 . Layout_ActivityAB, Layout_FragA, Layout_FragB.

setContentView (R.layout.Layout_ActivityAB) Activity AB. , u android, .

A B:

@Override
    //onCreateView is called when an instance of this class is first created.
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View rootView = inflater.inflate(R.layout.Layout_FragA, container, false);  return rootView;
    }

R.layout.Layout_FragA . Layout_FragA - .

0

All Articles