Experience solves the problem that fragment is still visible after replace

Source: Internet
Author: User

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:

  1. Fragmentmanager Fragmentmanager = Getsupportfragmentmanager ();
  2. Fragmenttransaction transaction = Fragmentmanager.begintransaction ();
  3. Orderfragment orderfragment = new Orderfragment ();
  4. Bundle args = new bundle ();
  5. Args.putint ("card_id", LoginHelper.currentCard.getId ());
  6. Args.putboolean ("Create_order", true);
  7. Orderfragment.setarguments (args);
  8. Transaction.replace (R.id.layout_shopping1, orderfragment);
  9. Transaction.addtobackstack (NULL);
  10. 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:

    1. <?xml version= "1.0" encoding= "Utf-8"?>
    2. <framelayout xmlns:android= "Http://schemas.android.com/apk/res/android"
    3. Android:id= "@+id/layout_shopping1"
    4. Android:layout_width= "Match_parent"
    5. android:layout_height= "Wrap_content"
    6. android:background= "@color/black" >
    7. </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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.