Most of the questions asked on the Internet refer to the replacement of fragment and the previous replacement is still shown there. I personally use the Android 2.3 +support development package, and a similar problem occurs on the 2.3 system. After searching the internet, it seems that no solution has been found. Then I groped myself. Finally found that the replacement Java code for fragment basically nothing, the Internet is correct, such as:
- Fragmentmanager Fragmentmanager = Getsupportfragmentmanager ();
- Fragmenttransaction transaction = Fragmentmanager.begintransaction ();
- Orderfragment orderfragment = new Orderfragment ();
- Bundle args = new bundle ();
- Args.putint ("card_id", LoginHelper.currentCard.getId ());
- Args.putboolean ("Create_order", true);
- Orderfragment.setarguments (args);
- Transaction.replace (R.id.layout_shopping1, orderfragment);
- Transaction.addtobackstack (NULL);
- Transaction.commit ();
Copy Code
But most people don't realize the importance of pasting XML layout files:
The correct approach is that you must use Framelayout as a layout container for fragment to be replaced
For example:
- <?xml version= "1.0" encoding= "Utf-8"?>
- <framelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
- Android:id= "@+id/layout_shopping1"
- Android:layout_width= "Match_parent"
- android:layout_height= "Wrap_content"
- android:background= "@color/black" >
- </FrameLayout>
Copy Code
Can not use such as linear layout linearlayout, etc., otherwise there will be visible problems.
Give a little experience and expect to help developers with similar problems.
Original: http://www.apkbus.com/android-121899-1-35.html
Experience solves the problem that fragment is still visible after replace