Fragment Fragment Class

Definition

A Fragment is a piece of an application's user interface or behavior that can be placed in an Activity.

[Android.Runtime.Register("android/app/Fragment", ApiSince=11, DoNotGenerateAcw=true)]
public class Fragment : Java.Lang.Object, Android.Content.IComponentCallbacks2, Android.Views.View.IOnCreateContextMenuListener, IDisposable
type Fragment = class
    inherit Object
    interface IComponentCallbacks2
    interface IComponentCallbacks
    interface IJavaObject
    interface IDisposable
    interface View.IOnCreateContextMenuListener
Inheritance
FragmentFragment
Derived
Attributes
Implements

Remarks

Android platform documentation

Portions of this page are modifications based on work created and shared by the Android Open Source Project and used according to terms described in the Creative Commons 2.5 Attribution License.

Constructors

Fragment() Fragment()

Default constructor.

Fragment(IntPtr, JniHandleOwnership) Fragment(IntPtr, JniHandleOwnership)

A constructor used when creating managed representations of JNI objects; called by the runtime.

Properties

Activity Activity

Return the Activity this fragment is currently associated with.

AllowEnterTransitionOverlap AllowEnterTransitionOverlap

Returns whether the the exit transition and enter transition overlap or not.

AllowReturnTransitionOverlap AllowReturnTransitionOverlap

Returns whether the the return transition and reenter transition overlap or not.

Arguments Arguments

Return the arguments supplied to Arguments, if any.

ChildFragmentManager ChildFragmentManager

Return a private FragmentManager for placing and managing Fragments inside of this Fragment.

Class Class

Returns the unique instance of Class that represents this object's class.

(Inherited from Object)
Context Context
EnterTransition EnterTransition

Returns the Transition that will be used to move Views into the initial scene.

ExitTransition ExitTransition

Returns the Transition that will be used to move Views out of the scene when the fragment is removed, hidden, or detached when not popping the back stack.

FragmentManager FragmentManager

Return the FragmentManager for interacting with fragments associated with this fragment's activity.

Handle Handle

The handle to the underlying Android instance.

(Inherited from Object)
Host Host
Id Id

Return the identifier this fragment is known by.

IJavaObjectEx.IsProxy IJavaObjectEx.IsProxy Inherited from Object
IJavaObjectEx.KeyHandle IJavaObjectEx.KeyHandle Inherited from Object
IJavaObjectEx.NeedsActivation IJavaObjectEx.NeedsActivation Inherited from Object
IJavaPeerable.JniManagedPeerState IJavaPeerable.JniManagedPeerState Inherited from Object
IsAdded IsAdded

Return true if the fragment is currently added to its activity.

IsDetached IsDetached

Return true if the fragment has been explicitly detached from the UI.

IsHidden IsHidden

Return true if the fragment has been hidden.

IsInLayout IsInLayout

Return true if the layout is included as part of an activity view hierarchy via the <fragment> tag.

IsRemoving IsRemoving

Return true if this fragment is currently being removed from its activity.

IsResumed IsResumed

Return true if the fragment is in the resumed state.

IsStateSaved IsStateSaved
IsVisible IsVisible

Return true if the fragment is currently visible to the user.

JniIdentityHashCode JniIdentityHashCode Inherited from Object
JniPeerMembers JniPeerMembers
LayoutInflater LayoutInflater
LoaderManager LoaderManager

Return the LoaderManager for this fragment, creating it if needed.

ParentFragment ParentFragment

Returns the parent Fragment containing this Fragment.

PeerReference PeerReference Inherited from Object
ReenterTransition ReenterTransition

Returns the Transition that will be used to move Views in to the scene when returning due to popping a back stack.

Resources Resources

Return getActivity().getResources().

RetainInstance RetainInstance
ReturnTransition ReturnTransition

Returns the Transition that will be used to move Views out of the scene when the Fragment is preparing to be removed, hidden, or detached because of popping the back stack.

SharedElementEnterTransition SharedElementEnterTransition

Returns the Transition that will be used for shared elements transferred into the content Scene.

SharedElementReturnTransition SharedElementReturnTransition

Return the Transition that will be used for shared elements transferred back during a pop of the back stack.

Tag Tag

Get the tag name of the fragment, if specified.

TargetFragment TargetFragment

Return the target fragment set by SetTargetFragment(Fragment, Int32).

TargetRequestCode TargetRequestCode

Return the target request code set by SetTargetFragment(Fragment, Int32).

ThresholdClass ThresholdClass

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

ThresholdType ThresholdType

This API supports the Mono for Android infrastructure and is not intended to be used directly from your code.

UserVisibleHint UserVisibleHint
View View

M:Android.App.Fragment.OnCreateView(Android.Views.LayoutInflater,Android.Views.ViewGroup,Android.Views.ViewGroup)

Methods

Clone() Clone()

Creates and returns a copy of this Object.

(Inherited from Object)
Dispose() Dispose() Inherited from Object
Dispose(Boolean) Dispose(Boolean) Inherited from Object
Dump(String, FileDescriptor, PrintWriter, String[]) Dump(String, FileDescriptor, PrintWriter, String[])

Print the Fragments's state into the given stream.

Equals(Object) Equals(Object)

Subclasses can not override equals().

GetHashCode() GetHashCode()

Subclasses can not override hashCode().

GetString(Int32) GetString(Int32)

Return a localized string from the application's package's default string table.

GetString(Int32, Object[]) GetString(Int32, Object[])
GetText(Int32) GetText(Int32)
GetTextFormatted(Int32) GetTextFormatted(Int32)

Return a localized, styled CharSequence from the application's package's default string table.

Instantiate(Context, String) Instantiate(Context, String)

M:Android.App.Fragment.Instantiate(Android.Content.Context,System.String,System.String)

Instantiate(Context, String, Bundle) Instantiate(Context, String, Bundle)

Create a new instance of a Fragment with the given class name.

JavaFinalize() JavaFinalize()

Invoked when the garbage collector has detected that this instance is no longer reachable.

(Inherited from Object)
Notify() Notify()

Causes a thread which is waiting on this object's monitor (by means of calling one of the wait() methods) to be woken up.

(Inherited from Object)
NotifyAll() NotifyAll()

Causes all threads which are waiting on this object's monitor (by means of calling one of the wait() methods) to be woken up.

(Inherited from Object)
OnActivityCreated(Bundle) OnActivityCreated(Bundle)

Called when the fragment's activity has been created and this fragment's view hierarchy instantiated.

OnActivityResult(Int32, Result, Intent) OnActivityResult(Int32, Result, Intent)

Receive the result from a previous call to StartActivityForResult(Intent, Int32).

OnAttach(Activity) OnAttach(Activity)
OnAttach(Context) OnAttach(Context)
OnAttachFragment(Fragment) OnAttachFragment(Fragment)
OnConfigurationChanged(Configuration) OnConfigurationChanged(Configuration)

Called by the system when the device configuration changes while your component is running.

OnContextItemSelected(IMenuItem) OnContextItemSelected(IMenuItem)

This hook is called whenever an item in a context menu is selected.

OnCreate(Bundle) OnCreate(Bundle)

Called to do initial creation of a fragment.

OnCreateAnimator(FragmentTransit, Boolean, Int32) OnCreateAnimator(FragmentTransit, Boolean, Int32)

Called when a fragment loads an animation.

OnCreateContextMenu(IContextMenu, View, IContextMenuContextMenuInfo) OnCreateContextMenu(IContextMenu, View, IContextMenuContextMenuInfo)

Called when a context menu for the view is about to be shown.

OnCreateOptionsMenu(IMenu, MenuInflater) OnCreateOptionsMenu(IMenu, MenuInflater)

Initialize the contents of the Activity's standard options menu.

OnCreateView(LayoutInflater, ViewGroup, Bundle) OnCreateView(LayoutInflater, ViewGroup, Bundle)

Called to have the fragment instantiate its user interface view.

OnDestroy() OnDestroy()

Called when the fragment is no longer in use.

OnDestroyOptionsMenu() OnDestroyOptionsMenu()

Called when this fragment's option menu items are no longer being included in the overall options menu.

OnDestroyView() OnDestroyView()

M:Android.App.Fragment.OnCreateView(Android.Views.LayoutInflater,Android.Views.ViewGroup,Android.Views.ViewGroup)

OnDetach() OnDetach()

Called when the fragment is no longer attached to its activity.

OnGetLayoutInflater(Bundle) OnGetLayoutInflater(Bundle)
OnHiddenChanged(Boolean) OnHiddenChanged(Boolean)

Called when the hidden state (as returned by IsHidden of the fragment has changed.

OnInflate(Activity, IAttributeSet, Bundle) OnInflate(Activity, IAttributeSet, Bundle)
OnInflate(Context, IAttributeSet, Bundle) OnInflate(Context, IAttributeSet, Bundle)
OnInflate(IAttributeSet, Bundle) OnInflate(IAttributeSet, Bundle)
OnLowMemory() OnLowMemory()

This is called when the overall system is running low on memory, and actively running processes should trim their memory usage.

OnMultiWindowModeChanged(Boolean) OnMultiWindowModeChanged(Boolean)
OnMultiWindowModeChanged(Boolean, Configuration) OnMultiWindowModeChanged(Boolean, Configuration)
OnOptionsItemSelected(IMenuItem) OnOptionsItemSelected(IMenuItem)

This hook is called whenever an item in your options menu is selected.

OnOptionsMenuClosed(IMenu) OnOptionsMenuClosed(IMenu)

This hook is called whenever the options menu is being closed (either by the user canceling the menu with the back/menu button, or when an item is selected).

OnPause() OnPause()

Called when the Fragment is no longer resumed.

OnPictureInPictureModeChanged(Boolean) OnPictureInPictureModeChanged(Boolean)
OnPictureInPictureModeChanged(Boolean, Configuration) OnPictureInPictureModeChanged(Boolean, Configuration)
OnPrepareOptionsMenu(IMenu) OnPrepareOptionsMenu(IMenu)

Prepare the Screen's standard options menu to be displayed.

OnRequestPermissionsResult(Int32, String[], Permission[]) OnRequestPermissionsResult(Int32, String[], Permission[])
OnResume() OnResume()

Called when the fragment is visible to the user and actively running.

OnSaveInstanceState(Bundle) OnSaveInstanceState(Bundle)

Called to ask the fragment to save its current dynamic state, so it can later be reconstructed in a new instance of its process is restarted.

OnStart() OnStart()

Called when the Fragment is visible to the user.

OnStop() OnStop()

Called when the Fragment is no longer started.

OnTrimMemory(TrimMemory) OnTrimMemory(TrimMemory)

Called when the operating system has determined that it is a good time for a process to trim unneeded memory from its process.

OnViewCreated(View, Bundle) OnViewCreated(View, Bundle)
OnViewStateRestored(Bundle) OnViewStateRestored(Bundle)

Called when all saved state has been restored into the view hierarchy of the fragment.

PostponeEnterTransition() PostponeEnterTransition()
RegisterForContextMenu(View) RegisterForContextMenu(View)

Registers a context menu to be shown for the given view (multiple views can show the context menu).

RequestPermissions(String[], Int32) RequestPermissions(String[], Int32)
SetEnterSharedElementCallback(SharedElementCallback) SetEnterSharedElementCallback(SharedElementCallback)

When custom transitions are used with Fragments, the enter transition callback is called when this Fragment is attached or detached when not popping the back stack.

SetExitSharedElementCallback(SharedElementCallback) SetExitSharedElementCallback(SharedElementCallback)

When custom transitions are used with Fragments, the exit transition callback is called when this Fragment is attached or detached when popping the back stack.

SetHandle(IntPtr, JniHandleOwnership) SetHandle(IntPtr, JniHandleOwnership)

Sets the Handle property.

(Inherited from Object)
SetHasOptionsMenu(Boolean) SetHasOptionsMenu(Boolean)

Report that this fragment would like to participate in populating the options menu by receiving a call to OnCreateOptionsMenu(IMenu, MenuInflater) and related methods.

SetInitialSavedState(Fragment+SavedState) SetInitialSavedState(Fragment+SavedState)

Set the initial saved state that this Fragment should restore itself from when first being constructed, as returned by SaveFragmentInstanceState(Fragment).

SetMenuVisibility(Boolean) SetMenuVisibility(Boolean)

Set a hint for whether this fragment's menu should be visible.

SetTargetFragment(Fragment, Int32) SetTargetFragment(Fragment, Int32)

Optional target for this fragment.

ShouldShowRequestPermissionRationale(String) ShouldShowRequestPermissionRationale(String)
StartActivity(Intent) StartActivity(Intent)

M:Android.Content.Context.StartActivity

StartActivity(Intent, Bundle) StartActivity(Intent, Bundle)

Android.App.Activity.startActivity(android.content.Intent,android.os.Bundle)

StartActivityForResult(Intent, Int32) StartActivityForResult(Intent, Int32)

Call StartActivityForResult(Intent, Int32) from the fragment's containing Activity.

StartActivityForResult(Intent, Int32, Bundle) StartActivityForResult(Intent, Int32, Bundle)

M:Android.App.Activity.StartActivityForResult(Android.Content.Intent,System.Int32,System.Int32)

StartIntentSenderForResult(IntentSender, Int32, Intent, ActivityFlags, ActivityFlags, Int32, Bundle) StartIntentSenderForResult(IntentSender, Int32, Intent, ActivityFlags, ActivityFlags, Int32, Bundle)
StartPostponedEnterTransition() StartPostponedEnterTransition()
ToArray<T>() ToArray<T>() Inherited from Object
ToString() ToString()

Returns a string containing a concise, human-readable description of this object.

(Inherited from Object)
UnregisterForContextMenu(View) UnregisterForContextMenu(View)

Prevents a context menu to be shown for the given view.

UnregisterFromRuntime() UnregisterFromRuntime() Inherited from Object
Wait() Wait()

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object.

(Inherited from Object)
Wait(Int64) Wait(Int64)

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.

(Inherited from Object)
Wait(Int64, Int32) Wait(Int64, Int32)

Causes the calling thread to wait until another thread calls the notify() or notifyAll() method of this object or until the specified timeout expires.

(Inherited from Object)

Explicit Interface Implementations

IJavaObjectEx.ToLocalJniHandle() IJavaObjectEx.ToLocalJniHandle() Inherited from Object
IJavaPeerable.Disposed() IJavaPeerable.Disposed() Inherited from Object
IJavaPeerable.DisposeUnlessReferenced() IJavaPeerable.DisposeUnlessReferenced() Inherited from Object
IJavaPeerable.Finalized() IJavaPeerable.Finalized() Inherited from Object
IJavaPeerable.SetJniIdentityHashCode(Int32) IJavaPeerable.SetJniIdentityHashCode(Int32) Inherited from Object
IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) Inherited from Object
IJavaPeerable.SetPeerReference(JniObjectReference) IJavaPeerable.SetPeerReference(JniObjectReference) Inherited from Object

Extension Methods

JavaCast<TResult>(IJavaObject) JavaCast<TResult>(IJavaObject)

Performs an Android runtime-checked type conversion.

JavaCast<TResult>(IJavaObject) JavaCast<TResult>(IJavaObject)
GetJniTypeName(IJavaPeerable) GetJniTypeName(IJavaPeerable)

Applies to