zoukankan      html  css  js  c++  java
  • 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. 

       

       

  • 相关阅读:
    01-SCOTT-SQL建表语句
    面试小题
    Swagger2使用API
    Elasticsearch单机安装_集群搭建_索引基本操作_Head插件安装与基本操作_ik分词器配置_logstash实现数据同步_教程
    45个非常有用的 Oracle 查询语句小结
    oracle获取定时时间段
    彻底理解webservice SOAP WSDL
    MySQL 1045登录失败
    quartz定时任务时间设置
    map 遍历的四种方式
  • 原文地址:https://www.cnblogs.com/gavinwu/p/3104555.html
Copyright © 2011-2022 走看看