ListFragment Class
Definition
Important
Some information relates to prerelease product that may be substantially modified before it’s released. Microsoft makes no warranties, express or implied, with respect to the information provided here.
This class was deprecated in API level 28.
[Android.Runtime.Register("android/app/ListFragment", DoNotGenerateAcw=true)]
public class ListFragment : Android.App.Fragment
[<Android.Runtime.Register("android/app/ListFragment", DoNotGenerateAcw=true)>]
type ListFragment = class
inherit Fragment
- Inheritance
- Attributes
Remarks
This class was deprecated in API level 28. Use the Support Library ListFragment for consistent behavior across all devices and access to Lifecycle.
A fragment that displays a list of items by binding to a data source such as an array or Cursor, and exposes event handlers when the user selects an item. ListFragment hosts a ListView object that can be bound to different data sources, typically either an array or a Cursor holding query results. Binding, screen layout, and row layout are discussed in the following sections. Screen Layout
ListFragment has a default layout that consists of a single list view. However, if you desire, you can customize the fragment layout by returning your own view hierarchy from onCreateView(LayoutInflater, ViewGroup, Bundle). To do this, your view hierarchy must contain a ListView object with the id ":id/list" (or R.id.list if it's in code) Optionally, your view hierarchy can contain another view object of any type to display when the list view is empty. This "empty list" notifier must have an id "android:empty". Note that when an empty view is present, the list view will be hidden when there is no data to display. The following code demonstrates an (ugly) custom list layout. It has a list with a green background, and an alternate red "no data" message.
Row Layout
You can specify the layout of individual rows in the list. You do this by specifying a layout resource in the ListAdapter object hosted by the fragment (the ListAdapter binds the ListView to the data; more on this later). A ListAdapter constructor takes a parameter that specifies a layout resource for each row. It also has two additional parameters that let you specify which data field to associate with which object in the row layout resource. These two parameters are typically parallel arrays.
Android provides some standard row layout resources. These are in the R.layout class, and have names such as simple_list_item_1, simple_list_item_2, and two_line_list_item. The following layout XML is the source for the resource two_line_list_item, which displays two data fields,one above the other, for each list row.
You must identify the data bound to each TextView object in this layout. The syntax for this is discussed in the next section.
Binding to Data
You bind the ListFragment's ListView object to data using a class that implements the ListAdapter interface. Android provides two standard list adapters: SimpleAdapter for static data (Maps), and SimpleCursorAdapter for Cursor query results.
You must use ListFragment.setListAdapter() to associate the list with an adapter. Do not directly call ListView.setAdapter() or else important initialization will be skipped.
Android reference for android.app.ListFragment.
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
| Name | Description |
|---|---|
| ListFragment() | |
| ListFragment(IntPtr, JniHandleOwnership) |
Initializes a managed representation of an existing Java Native Interface object. |
Properties
| Name | Description |
|---|---|
| Activity |
Return the Activity this fragment is currently associated with. (Inherited from Fragment) |
| AllowEnterTransitionOverlap |
Returns whether the exit transition and enter transition overlap or not. (Inherited from Fragment) |
| AllowReturnTransitionOverlap |
Returns whether the return transition and reenter transition overlap or not. (Inherited from Fragment) |
| Arguments |
Return the arguments supplied to setArguments(Bundle), if any. (Inherited from Fragment) |
| ChildFragmentManager |
Return a private FragmentManager for placing and managing Fragments inside of this Fragment. (Inherited from Fragment) |
| Class |
Returns the runtime class of this |
| Context |
Return the Context this fragment is currently associated with. (Inherited from Fragment) |
| EnterTransition |
Returns the Transition that will be used to move Views into the initial scene. (Inherited from Fragment) |
| 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. (Inherited from Fragment) |
| FragmentManager |
Return the FragmentManager for interacting with fragments associated with this fragment's activity. (Inherited from Fragment) |
| Handle |
The handle to the underlying Android instance. (Inherited from Object) |
| Host |
Return the host object of this fragment. (Inherited from Fragment) |
| Id |
Return the identifier this fragment is known by. (Inherited from Fragment) |
| IsAdded |
Return true if the fragment is currently added to its activity. (Inherited from Fragment) |
| IsDetached |
Return true if the fragment has been explicitly detached from the UI. (Inherited from Fragment) |
| IsHidden |
Return true if the fragment has been hidden. (Inherited from Fragment) |
| IsInLayout |
Return true if the layout is included as part of an activity view hierarchy via the <fragment> tag. (Inherited from Fragment) |
| IsRemoving |
Return true if this fragment is currently being removed from its activity. (Inherited from Fragment) |
| IsResumed |
Return true if the fragment is in the resumed state. (Inherited from Fragment) |
| IsStateSaved |
Returns true if this fragment is added and its state has already been saved by its host. (Inherited from Fragment) |
| IsVisible |
Return true if the fragment is currently visible to the user. (Inherited from Fragment) |
| JniIdentityHashCode |
Gets the identity hash code assigned to this Java peer by the interop runtime. (Inherited from Object) |
| JniManagedPeerState | (Inherited from JavaObject) |
| JniPeerMembers |
Provides JNI binding infrastructure for Android.App.ListFragment. |
| LayoutInflater |
Returns the cached LayoutInflater used to inflate Views of this Fragment. (Inherited from Fragment) |
| ListAdapter |
Get the ListAdapter associated with this fragment's ListView. |
| ListView |
Get the fragment's list view widget. |
| LoaderManager |
This method is deprecated. (Inherited from Fragment) |
| ParentFragment |
Returns the parent Fragment containing this Fragment. (Inherited from Fragment) |
| PeerReference |
Gets the JNI object reference for this Java peer. (Inherited from Object) |
| ReenterTransition |
Returns the Transition that will be used to move Views in to the scene when returning due to popping a back stack. (Inherited from Fragment) |
| Resources |
Return getActivity().getResources(). (Inherited from Fragment) |
| RetainInstance |
Control whether a fragment instance is retained across Activity re-creation (such as from a configuration change). (Inherited from Fragment) |
| 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. (Inherited from Fragment) |
| SelectedItemId |
Get the cursor row ID of the currently selected list item. |
| SelectedItemPosition |
Get the position of the currently selected list item. |
| SharedElementEnterTransition |
Returns the Transition that will be used for shared elements transferred into the content Scene. (Inherited from Fragment) |
| SharedElementReturnTransition |
Return the Transition that will be used for shared elements transferred back during a pop of the back stack. (Inherited from Fragment) |
| Tag |
Get the tag name of the fragment, if specified. (Inherited from Fragment) |
| TargetFragment |
Return the target fragment set by setTargetFragment(Fragment, int). (Inherited from Fragment) |
| TargetRequestCode |
Return the target request code set by setTargetFragment(Fragment, int). (Inherited from Fragment) |
| ThresholdClass |
Provides JNI binding infrastructure for Android.App.ListFragment. |
| ThresholdType |
Provides JNI binding infrastructure for Android.App.ListFragment. |
| UserVisibleHint |
See also: (Inherited from Fragment) |
| View |
Get the root view for the fragment's layout (the one returned by onCreateView(LayoutInflater, ViewGroup, Bundle)), if provided. (Inherited from Fragment) |
Methods
| Name | Description |
|---|---|
| Clone() |
Creates and returns a copy of this object. (Inherited from Object) |
| Construct(JniObjectReference, JniObjectReferenceOptions) | (Inherited from JavaObject) |
| Dispose() |
Releases the resources held by this Java peer. (Inherited from Object) |
| Dispose(Boolean) |
Releases the resources held by this Java peer. (Inherited from Object) |
| DisposeUnlessReferenced() | (Inherited from JavaObject) |
| Dump(String, FileDescriptor, PrintWriter, String[]) |
Print the Fragments's state into the given stream. (Inherited from Fragment) |
| Equals(Object) | (Inherited from JavaObject) |
| Equals(Object) |
Obsolete.
Subclasses can not override equals(). (Inherited from Fragment) |
| GetHashCode() |
Obsolete.
Subclasses can not override hashCode(). (Inherited from Fragment) |
| GetString(Int32, Object[]) |
Return a localized formatted string from the application's package's default string table, substituting the format arguments as defined in Formatter and String.format(String, Object). (Inherited from Fragment) |
| GetString(Int32) |
Return a localized string from the application's package's default string table. (Inherited from Fragment) |
| GetText(Int32) |
Return a localized, styled CharSequence from the application's package's default string table. (Inherited from Fragment) |
| GetTextFormatted(Int32) |
Return a localized, styled CharSequence from the application's package's default string table. (Inherited from Fragment) |
| JavaFinalize() |
Called by the garbage collector on an object when garbage collection determines that there are no more references to the object. (Inherited from Object) |
| Notify() |
Wakes up a single thread that is waiting on this object's monitor. (Inherited from Object) |
| NotifyAll() |
Wakes up all threads that are waiting on this object's monitor. (Inherited from Object) |
| OnActivityCreated(Bundle) |
Called when the fragment's activity has been created and this fragment's view hierarchy instantiated. (Inherited from Fragment) |
| OnActivityResult(Int32, Result, Intent) |
Receive the result from a previous call to startActivityForResult(Intent,int). (Inherited from Fragment) |
| OnAttach(Activity) |
This method was deprecated in API level 23. (Inherited from Fragment) |
| OnAttach(Context) |
Called when a fragment is first attached to its context. (Inherited from Fragment) |
| OnAttachFragment(Fragment) |
Called when a fragment is attached as a child of this fragment. (Inherited from Fragment) |
| OnConfigurationChanged(Configuration) |
Called by the system when the device configuration changes while your component is running. (Inherited from Fragment) |
| OnContextItemSelected(IMenuItem) |
This hook is called whenever an item in a context menu is selected. (Inherited from Fragment) |
| OnCreate(Bundle) |
Called to do initial creation of a fragment. (Inherited from Fragment) |
| OnCreateAnimator(FragmentTransit, Boolean, Int32) |
Called when a fragment loads an animation. (Inherited from Fragment) |
| OnCreateContextMenu(IContextMenu, View, IContextMenuContextMenuInfo) |
Called when a context menu for the view is about to be shown. (Inherited from Fragment) |
| OnCreateOptionsMenu(IMenu, MenuInflater) |
Initialize the contents of the Activity's standard options menu. (Inherited from Fragment) |
| OnCreateView(LayoutInflater, ViewGroup, Bundle) |
Called to have the fragment instantiate its user interface view. (Inherited from Fragment) |
| OnDestroy() |
Called when the fragment is no longer in use. (Inherited from Fragment) |
| OnDestroyOptionsMenu() |
Called when this fragment's option menu items are no longer being included in the overall options menu. (Inherited from Fragment) |
| OnDestroyView() |
Called when the view previously created by onCreateView(LayoutInflater, ViewGroup, Bundle) has been detached from the fragment. (Inherited from Fragment) |
| OnDetach() |
Called when the fragment is no longer attached to its activity. (Inherited from Fragment) |
| OnGetLayoutInflater(Bundle) |
Returns the LayoutInflater used to inflate Views of this Fragment. (Inherited from Fragment) |
| OnHiddenChanged(Boolean) |
Called when the hidden state (as returned by isHidden() of the fragment has changed. (Inherited from Fragment) |
| OnInflate(Activity, IAttributeSet, Bundle) |
This method was deprecated in API level 23. (Inherited from Fragment) |
| OnInflate(Context, IAttributeSet, Bundle) |
Called when a fragment is being created as part of a view layout inflation, typically from setting the content view of an activity. (Inherited from Fragment) |
| OnInflate(IAttributeSet, Bundle) |
Obsolete.
This method was deprecated in API level 15. (Inherited from Fragment) |
| OnListItemClick(ListView, View, Int32, Int64) |
This method will be called when an item in the list is selected. |
| OnLowMemory() |
This is called when the overall system is running low on memory, and actively running processes should trim their memory usage. (Inherited from Fragment) |
| OnMultiWindowModeChanged(Boolean, Configuration) |
Called when the Fragment's activity changes from fullscreen mode to multi-window mode and visa-versa. (Inherited from Fragment) |
| OnMultiWindowModeChanged(Boolean) |
This method was deprecated in API level 26. (Inherited from Fragment) |
| OnOptionsItemSelected(IMenuItem) |
This hook is called whenever an item in your options menu is selected. (Inherited from Fragment) |
| 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). (Inherited from Fragment) |
| OnPause() |
Called when the Fragment is no longer resumed. (Inherited from Fragment) |
| OnPictureInPictureModeChanged(Boolean, Configuration) |
Called by the system when the activity changes to and from picture-in-picture mode. (Inherited from Fragment) |
| OnPictureInPictureModeChanged(Boolean) |
This method was deprecated in API level 26. (Inherited from Fragment) |
| OnPrepareOptionsMenu(IMenu) |
Prepare the Screen's standard options menu to be displayed. (Inherited from Fragment) |
| OnRequestPermissionsResult(Int32, String[], Permission[]) |
Callback for the result from requesting permissions. (Inherited from Fragment) |
| OnResume() |
Called when the fragment is visible to the user and actively running. (Inherited from Fragment) |
| 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. (Inherited from Fragment) |
| OnStart() |
Called when the Fragment is visible to the user. (Inherited from Fragment) |
| OnStop() |
Called when the Fragment is no longer started. (Inherited from Fragment) |
| 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. (Inherited from Fragment) |
| OnViewCreated(View, Bundle) |
Called immediately after onCreateView(LayoutInflater,ViewGroup,Bundle) has returned, but before any saved state has been restored in to the view. (Inherited from Fragment) |
| OnViewStateRestored(Bundle) |
Called when all saved state has been restored into the view hierarchy of the fragment. (Inherited from Fragment) |
| PostponeEnterTransition() |
Postpone the entering Fragment transition until startPostponedEnterTransition() or FragmentManager.executePendingTransactions() has been called. (Inherited from Fragment) |
| RegisterForContextMenu(View) |
Registers a context menu to be shown for the given view (multiple views can show the context menu). (Inherited from Fragment) |
| RequestPermissions(String[], Int32) |
Requests permissions to be granted to this application. (Inherited from Fragment) |
| SetEmptyText(ICharSequence) |
The default content for a ListFragment has a TextView that can be shown when the list is empty. |
| SetEmptyText(String) |
The default content for a ListFragment has a TextView that can be shown when the list is empty. |
| 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. (Inherited from Fragment) |
| 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. (Inherited from Fragment) |
| SetHandle(IntPtr, JniHandleOwnership) |
Sets the Handle property. (Inherited from Object) |
| SetHasOptionsMenu(Boolean) |
Report that this fragment would like to participate in populating the options menu by receiving a call to onCreateOptionsMenu(Menu, MenuInflater) and related methods. (Inherited from Fragment) |
| SetInitialSavedState(Fragment+SavedState) |
Set the initial saved state that this Fragment should restore itself from when first being constructed, as returned by FragmentManager.saveFragmentInstanceState. (Inherited from Fragment) |
| SetListShown(Boolean) |
Control whether the list is being displayed. |
| SetListShownNoAnimation(Boolean) |
Like setListShown(boolean), but no animation is used when transitioning from the previous state. |
| SetMenuVisibility(Boolean) |
Set a hint for whether this fragment's menu should be visible. (Inherited from Fragment) |
| SetPeerReference(JniObjectReference, JniObjectReferenceOptions) | (Inherited from JavaObject) |
| SetSelection(Int32) |
Set the currently selected list item to the specified position with the adapter's data |
| SetTargetFragment(Fragment, Int32) |
Optional target for this fragment. (Inherited from Fragment) |
| ShouldShowRequestPermissionRationale(String) |
Gets whether you should show UI with rationale before requesting a permission. (Inherited from Fragment) |
| StartActivity(Intent, Bundle) |
Call Activity.startActivity(Intent,Bundle) from the fragment's containing Activity. (Inherited from Fragment) |
| StartActivity(Intent) |
Call Activity.startActivity(Intent) from the fragment's containing Activity. (Inherited from Fragment) |
| StartActivityForResult(Intent, Int32, Bundle) |
Call Activity.startActivityForResult(Intent,int,Bundle) from the fragment's containing Activity. (Inherited from Fragment) |
| StartActivityForResult(Intent, Int32) |
Call Activity.startActivityForResult(Intent,int) from the fragment's containing Activity. (Inherited from Fragment) |
| StartIntentSenderForResult(IntentSender, Int32, Intent, ActivityFlags, ActivityFlags, Int32, Bundle) |
Call Activity.startIntentSenderForResult(IntentSender,int,Intent,int,int,int,Bundle) from the fragment's containing Activity. (Inherited from Fragment) |
| StartPostponedEnterTransition() |
Begin postponed transitions after postponeEnterTransition() was called. (Inherited from Fragment) |
| ToArray<T>() |
Creates a managed array from this Java array wrapper. (Inherited from Object) |
| ToString() |
Returns a string representation of the object. (Inherited from Object) |
| UnregisterForContextMenu(View) |
Prevents a context menu to be shown for the given view. (Inherited from Fragment) |
| UnregisterFromRuntime() |
Unregisters this Java peer from the interop runtime. (Inherited from Object) |
| Wait() |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>. (Inherited from Object) |
| Wait(Int64, Int32) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
| Wait(Int64) |
Causes the current thread to wait until it is awakened, typically by being <em>notified</em> or <em>interrupted</em>, or until a certain amount of real time has elapsed. (Inherited from Object) |
Explicit Interface Implementations
| Name | Description |
|---|---|
| IJavaPeerable.Disposed() | (Inherited from JavaObject) |
| IJavaPeerable.Finalized() | (Inherited from JavaObject) |
| IJavaPeerable.JniObjectReferenceControlBlock | (Inherited from JavaObject) |
| IJavaPeerable.SetJniIdentityHashCode(Int32) | (Inherited from JavaObject) |
| IJavaPeerable.SetJniManagedPeerState(JniManagedPeerStates) | (Inherited from JavaObject) |
| IJavaPeerable.SetPeerReference(JniObjectReference) | (Inherited from JavaObject) |
| IJavaPeerable.UnregisterFromRuntime() | (Inherited from Fragment) |
Extension Methods
| Name | Description |
|---|---|
| GetJniTypeName(IJavaPeerable) |
Gets the JNI name of the type of the instance |
| JavaAs<TResult>(IJavaPeerable) |
Try to coerce |
| JavaCast<TResult>(IJavaObject) |
Performs an Android runtime-checked type conversion. |
| JavaCast<TResult>(IJavaObject) | |
| TryJavaCast<TResult>(IJavaPeerable, TResult) |
Try to coerce |