The fragment of Android learning

Source: Internet
Author: User

Fragment is a controller object that allows activity to manage user interfaces through fragment, which can be part of a full screen or a full screen. The fragment view contains a visual UI element that the user can interact with, but the fragment view itself does not have the ability to display the view on the screen, and the fragment can be displayed on the screen only if its view is placed on the activity's view hierarchy. Therefore, the activity view contains a location that can be inserted into the fragment view. This knowledge point solves the doubts of my last article.

Therefore, the use of fragment requires activity support, and activity can provide such support. In order to manage the UI fragment,activity need to be able to position and manage the life cycle of the fragment in the layout for fragment views. Fragmentmanager is responsible for managing fragment and adding their views to the activity's view hierarchy. The first step is to get the Fragmanager object itself by calling the Getfragmentmanager () method directly through the Getsupportmanager () method (if you do not need to support a lower version of the device). This object is then used to manage the fragment transaction. Fragment transactions are fragment that are used to add, remove, attach, and detach fragment queues. The life cycle of the fragment is similar to the activity life cycle, which also stops, pauses, runs, and so on. The life cycle method of the fragment is called by the managed activity, not by the operating system.

1 public View Oncreateview (layoutinflater inflater,viewgroup parent,bundle savedinstancestate)

     generates a layout for the fragment view by this method, and then returns the resulting view to the managed activity. Generates a fragment view by using the Layoutinflater.inflate () method to pass in the resource ID of the layout. The second parameter is the parent view of the view, and usually we need the parent view to properly configure the group. The bundle contains the data that the method uses to reconstruct the view in a saved state.

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.