Android class reference --- Fragment (3)

Source: Internet
Author: User

Class description

1. Nested classes

Class Fragment. InstantiationException

If an instantiation error occurs, the exception class is thrown through the instantiate (Context, String, Bundle) method.

Class Fragment. SavedState

You can use the FragmentManager. saveFragmentInstanceState (Fragment) method to obtain the status information to save from a Fragment object instance.

2. inherited Constants

From interface: android. content. ComponentCallbacks2

3. Public constructor and Method

Public Fragment ()

Default constructor. Each Fragment class must have an empty constructor so that it can be used to instantiate the Fragment object when the Activity is restored. It is strongly recommended that any subclass of Fragment do not have any constructors with parameters, because these constructors will not be called when the Fragment is re-instantiated. Instead, they can be called by setArguments (Bundle) the method provides the parameter to the caller and can be obtained using the getArguments () method of Fragment.

Generally, applications should not implement this constructor. Use the onAttach (Activity) method to associate the Fragment object with the Activity object where the Fragment object is to be run for the first time. Some applications may also want to implement the onInflate (Activity, AttributeSet, Bundle) method to obtain attributes from the layout resource, but because the Fragment object is bound to the Activity, this method should be used with caution.

Public void dump (String prefix, FileDescriptor fd, PrintWriter writer, String [] args)

This method prints the state of the Fragment object to the given binary stream.

Parameters:

Prefix: the text to be printed before each line.

Fd: the original file descriptor to which the transfer information is sent.

Writer: Specifies the PrintWriter object that receives the stored state. After this method is returned, the PrintWriter object will be closed.

Args: specify additional parameters for the transfer request.

Public final boolean equals (Object o)

This method is overwritten by sub-classes.

Parameters:

O: Specifies the object to be compared with this instance.

Return Value:

True: the specified object is equal to the current object. false: not equal.

Public final Activity getActivity ()

Returns the Activity object associated with the Fragment object.

Public final Bundle getArguments ()

Returns the parameters provided when the Fragment object is instantiated.

Public final FragmentManager getFragmentManager ()

Returns the manager --- FragmentManager object of all Fragment objects associated with the Activity of the Fragment. Note that the method returns null until the Fragment object is placed in the FragmentTransaction object until it is submitted to the Activity it is bound.

Public final int getId ()

This method returns the identifier of the Fragment object, which can be the android: id attribute value provided in the layout, or the container View ID provided when the Fragment object is added.

Public LoaderManager getLoaderManager ()

Returns the LoaderManager object for this Fragment object. If necessary, create it.

Public final Resources getResources ()

This method returns the resources associated with the Fragment object.

Public final boolean getRetainInstance ()

 

Public final String getString (int resId)

Returns a localized string from the default string table of the application package.

Parameters:

The resource ID of the string to be retrieved by resId.

Public final String getString (int resId, Object... FormatArgs)

Returns a localized formatted String from the default String table of the application package, using format (String, Object…) in the Formatter Object ...) To replace the formatted parameters.

Parameters:

ResId specifies the resource id of the formatted string

FormatArgs specifies the formatting parameter to be replaced

Public final String getTag ()

If the Fragment object is specified, use this method to obtain the name of the Fragment object.

Public final Fragment getTargetFragment ()

Returns the target Fragment object set by the setTargetFragment (Fragment, int) method.

Public final int getTargetRequestCode ()

Returns the target Request Encoding set by the setTargetFragment (Fragment, int) method.

Public final CharSequence getText (int resId)

Return the specified localized and styled CharSequence object from the default string table of the application package.

Parameters:

ResId specifies the resource id of the CharSequence object text to be obtained.

Public final getUserVisibleHint ()

Returns the value of the prompt information displayed to the user on the Fragment object.

Public View getView ()

Obtains the root View object of the Fragment object layout. If no layout exists, null is returned.

Public final int hashCode ()

The subclass cannot overwrite this method. Returns the hash code of the object.

Public static Fragment instantiate (Context context, String fname)

Except for the Bundle parameter, the other methods are the same as those of instantiate (Context, String, Bundle.

Public static Fragment instantiate (Context context, String fname, Bundle args)

Create a new Fragment object instance with the given class name. It is the same as calling an empty constructor.

Parameters:

Context refers to the context to be used when the Fragment object is instantiated. Currently, it is only used to obtain its class loader --- ClassLoader object.

The name of the Fragment class to be instantiated by fname.

Args specifies the Bundle parameter to be provided to the Fragment object. You can use the getArguments () method to obtain the parameter. It can also be null.

Returns a new Fragment object instance.

Throws)

InstantiationException if an error occurs when instantiating a given Fragment class, this runtime exception is thrown, which is generally not expected to happen.

 

 

From FireOfStar's column

Related Article

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.