• APP Activities Fragments


    http://developer.android.com/guide/components/fragments.html

    1. Fragments

        A Fragment represents a behavior or a portion of the user interface in an Activity.

                                         a modular section of an activity.

        A Fragment must always be embedded in an activity, and its lifecycle is directly affected by the host activity's lifecycle.

        Each back stack entry in the activity is a record of the fragment transaction that occured.

        Adding a fragment:

            (1) declare the fragment in the activity's layout file, as a <fragment> element.

            (2) add a fragment by adding it to an existing ViewGroup .

       A Fragment is not required to be a part of the activity layout, it can be used as an invisible worker without its own UI.

    2. Creating a fragment

        implementing at least the following lifecycle methods.

    onCreate()
    The system calls this when creating the fragment. Within your implementation, you should initialize essential components of the fragment that you want to retain when the fragment is paused or stopped, then resumed.
    onCreateView()
    The system calls this when it's time for the fragment to draw its user interface for the first time. To draw a UI for your fragment, you must return a View from this method that is the root of your fragment's layout. You can return null if the fragment does not provide a UI.
    onPause()
    The system calls this method as the first indication that the user is leaving the fragment (though it does not always mean the fragment is being destroyed). This is usually where you should commit any changes that should be persisted beyond the current user session (because the user might not come back).

    There are also a few subclasses that you might want to extend, instead of the base Fragment class:

    DialogFragment
    Displays a floating dialog. Using this class to create a dialog is a good alternative to using the dialog helper methods in the Activity class, because you can incorporate a fragment dialog into the back stack of fragments managed by the activity, allowing the user to return to a dismissed fragment.
    ListFragment
    Displays a list of items that are managed by an adapter (such as a SimpleCursorAdapter), similar to ListActivity. It provides several methods for managing a list view, such as the onListItemClick() callback to handle click events.
    PreferenceFragment
    Displays a hierarchy of Preference objects as a list, similar to PreferenceActivity. This is useful when creating a "settings" activity for your application.

    3. Adding a user interface

        To provide a layout for a fragment, you must implement the onCreateView() callback method, which the Android system calls when it's time for the fragment to draw its layout. Your implementation of this method must return a View that is the root of your fragment's layout. 

       

       

  • 相关阅读:
    翻译:实时通信协议UDP-RT——Michael Pan
    翻译:为DAW优化Windows
    翻译:Windows and Real-Time——Daniel Terhell
    笔记4:IIS6发布网站后“对XX路径的访问被拒绝”
    杂记3:VS使用Web Deploy一键发布网站到服务器
    杂记2:VS2013创建Windows服务实现自动发送邮件
    杂记1:不安装Oracle客户端远程连接Oracle的方法
    DevExpress随笔系列
    DevExpress(5): ASPxUploadControl上传照片后用ASPxBinaryImage展示
    DevExpress(4): ASPxGridView随笔
  • 原文地址:https://www.cnblogs.com/gavinwu/p/3104555.html
Copyright © 2020-2023  润新知