Added in API level 1

AdapterView


abstract class AdapterView<T : Adapter!> : ViewGroup
kotlin.Any
   ↳ android.view.View
   ↳ android.view.ViewGroup
   ↳ android.widget.AdapterView

An AdapterView is a view whose children are determined by an Adapter.

See ListView, GridView, Spinner and Gallery for commonly used subclasses of AdapterView.

Summary

Nested classes
open

Extra menu information provided to the android.view.View.OnCreateContextMenuListener#onCreateContextMenu(ContextMenu, View, ContextMenuInfo) callback when a context menu is brought up for this AdapterView.

abstract

Interface definition for a callback to be invoked when an item in this AdapterView has been clicked.

abstract

Interface definition for a callback to be invoked when an item in this view has been clicked and held.

abstract

Interface definition for a callback to be invoked when an item in this view has been selected.

Inherited XML attributes
Constants
static Int

Represents an invalid position.

static Long

Represents an empty or invalid row id

static Int

The item view type returned by Adapter.getItemViewType(int) when the item is a header or footer.

static Int

The item view type returned by Adapter.getItemViewType(int) when the adapter does not want the item's view recycled.

Inherited constants
Public constructors
AdapterView(context: Context!)

AdapterView(context: Context!, attrs: AttributeSet!)

AdapterView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int)

AdapterView(context: Context!, attrs: AttributeSet!, defStyleAttr: Int, defStyleRes: Int)

Public methods
open Unit
addView(child: View!)

This method is not supported and throws an UnsupportedOperationException when called.

open Unit
addView(child: View!, params: ViewGroup.LayoutParams!)

This method is not supported and throws an UnsupportedOperationException when called.

open Unit
addView(child: View!, index: Int)

This method is not supported and throws an UnsupportedOperationException when called.

open Unit
addView(child: View!, index: Int, params: ViewGroup.LayoutParams!)

This method is not supported and throws an UnsupportedOperationException when called.

open CharSequence!

abstract T

Returns the adapter currently associated with this widget.

open Int

open View!

When the current adapter is empty, the AdapterView can display a special view called the empty view.

open Int

Returns the position within the adapter's data set for the first item displayed on screen.

open Any!

Gets the data associated with the specified position in the list.

open Long

open Int

Returns the position within the adapter's data set for the last item displayed on screen.

AdapterView.OnItemClickListener?

AdapterView.OnItemLongClickListener!

AdapterView.OnItemSelectedListener?

open Int

Returns the position within the adapter's data set for the view, where view is a an adapter item or a descendant of an adapter item.

open Any!

open Long

open Int

Return the position of the currently selected item within the adapter's data set

abstract View!

open Unit

Populates a ViewStructure to fullfil an autofill request.

open Boolean
performItemClick(view: View!, position: Int, id: Long)

Call the OnItemClickListener, if it is defined.

open Unit

This method is not supported and throws an UnsupportedOperationException when called.

open Unit
removeView(child: View!)

This method is not supported and throws an UnsupportedOperationException when called.

open Unit
removeViewAt(index: Int)

This method is not supported and throws an UnsupportedOperationException when called.

abstract Unit
setAdapter(adapter: T)

Sets the adapter that provides the data and the views to represent the data in this widget.

open Unit
setEmptyView(emptyView: View!)

Sets the view to show if the adapter is empty

open Unit
setFocusable(focusable: Int)

Sets whether this view can receive focus.

open Unit

open Unit

open Unit

Register a callback to be invoked when an item in this AdapterView has been clicked.

open Unit

Register a callback to be invoked when an item in this AdapterView has been clicked and held

open Unit

Register a callback to be invoked when an item in this AdapterView has been selected.

abstract Unit
setSelection(position: Int)

Sets the currently selected item.

Protected methods
open Boolean

open Unit

Override to prevent thawing of any views created by the adapter.

open Unit

Override to prevent freezing of any views created by the adapter.

open Unit

open Unit
onLayout(changed: Boolean, left: Int, top: Int, right: Int, bottom: Int)

Inherited functions
Inherited properties

Constants

INVALID_POSITION

Added in API level 1
static val INVALID_POSITION: Int

Represents an invalid position. All valid positions are in the range 0 to 1 less than the number of items in the current adapter.

Value: -1

INVALID_ROW_ID

Added in API level 1
static val INVALID_ROW_ID: Long

Represents an empty or invalid row id

Value: -9223372036854775808L
Added in API level 1
static val ITEM_VIEW_TYPE_HEADER_OR_FOOTER: Int

The item view type returned by Adapter.getItemViewType(int) when the item is a header or footer.

Value: -2

ITEM_VIEW_TYPE_IGNORE

Added in API level 1
static val ITEM_VIEW_TYPE_IGNORE: Int

The item view type returned by Adapter.getItemViewType(int) when the adapter does not want the item's view recycled.

Value: -1

Public constructors

AdapterView

Added in API level 1
AdapterView(context: Context!)

AdapterView

Added in API level 1
AdapterView(
    context: Context!,
    attrs: AttributeSet!)

AdapterView

Added in API level 1
AdapterView(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int)

AdapterView

Added in API level 21
AdapterView(
    context: Context!,
    attrs: AttributeSet!,
    defStyleAttr: Int,
    defStyleRes: Int)

Public methods

addView

Added in API level 1
open fun addView(child: View!): Unit

This method is not supported and throws an UnsupportedOperationException when called.

Parameters
child View!: Ignored.
Exceptions
java.lang.UnsupportedOperationException Every time this method is invoked.

addView

Added in API level 1
open fun addView(
    child: View!,
    params: ViewGroup.LayoutParams!
): Unit

This method is not supported and throws an UnsupportedOperationException when called.

Parameters
view The view to be added to this window.
params ViewGroup.LayoutParams!: Ignored.
child View!: Ignored.
Exceptions
java.lang.UnsupportedOperationException Every time this method is invoked.

addView

Added in API level 1
open fun addView(
    child: View!,
    index: Int
): Unit

This method is not supported and throws an UnsupportedOperationException when called.

Parameters
child View!: Ignored.
index Int: Ignored.
Exceptions
java.lang.UnsupportedOperationException Every time this method is invoked.

addView

Added in API level 1
open fun addView(
    child: View!,
    index: Int,
    params: ViewGroup.LayoutParams!
): Unit

This method is not supported and throws an UnsupportedOperationException when called.

Parameters
child View!: Ignored.
index Int: Ignored.
params ViewGroup.LayoutParams!: Ignored.
Exceptions
java.lang.UnsupportedOperationException Every time this method is invoked.

getAccessibilityClassName

Added in API level 23
open fun getAccessibilityClassName(): CharSequence!

getAdapter

Added in API level 1
abstract fun getAdapter(): T

Returns the adapter currently associated with this widget.

Return
T The adapter used to provide this view's content.

getCount

Added in API level 1
open fun getCount(): Int
Return
Int The number of items owned by the Adapter associated with this AdapterView. (This is the number of data items, which may be larger than the number of visible views.)

getEmptyView

Added in API level 1
open fun getEmptyView(): View!

When the current adapter is empty, the AdapterView can display a special view called the empty view. The empty view is used to provide feedback to the user that no data is available in this AdapterView.

Return
View! The view to show if the adapter is empty.

getFirstVisiblePosition

Added in API level 1
open fun getFirstVisiblePosition(): Int

Returns the position within the adapter's data set for the first item displayed on screen.

Return
Int The position within the adapter's data set

getItemAtPosition

Added in API level 1
open fun getItemAtPosition(position: Int): Any!

Gets the data associated with the specified position in the list.

Parameters
position Int: Which data to get
Return
Any! The data associated with the specified position in the list

getItemIdAtPosition

Added in API level 1
open fun getItemIdAtPosition(position: Int): Long

getLastVisiblePosition

Added in API level 1
open fun getLastVisiblePosition(): Int

Returns the position within the adapter's data set for the last item displayed on screen.

Return
Int The position within the adapter's data set

getOnItemClickListener

Added in API level 1
fun getOnItemClickListener(): AdapterView.OnItemClickListener?
Return
AdapterView.OnItemClickListener? The callback to be invoked with an item in this AdapterView has been clicked, or null if no callback has been set.

getOnItemLongClickListener

Added in API level 1
fun getOnItemLongClickListener(): AdapterView.OnItemLongClickListener!
Return
AdapterView.OnItemLongClickListener! The callback to be invoked with an item in this AdapterView has been clicked and held, or null if no callback has been set.

getOnItemSelectedListener

Added in API level 1
fun getOnItemSelectedListener(): AdapterView.OnItemSelectedListener?
Return
AdapterView.OnItemSelectedListener? This value may be null.

getPositionForView

Added in API level 1
open fun getPositionForView(view: View!): Int

Returns the position within the adapter's data set for the view, where view is a an adapter item or a descendant of an adapter item.

Note: The result of this method only reflects the position of the data bound to view during the most recent layout pass. If the adapter's data set has changed without a subsequent layout pass, the position returned by this method may not match the current position of the data within the adapter.

Parameters
view View!: an adapter item, or a descendant of an adapter item. This must be visible in this AdapterView at the time of the call.
Return
Int the position within the adapter's data set of the view, or INVALID_POSITION if the view does not correspond to a list item (or it is not currently visible)

getSelectedItem

Added in API level 1
open fun getSelectedItem(): Any!
Return
Any! The data corresponding to the currently selected item, or null if there is nothing selected.

getSelectedItemId

Added in API level 1
open fun getSelectedItemId(): Long
Return
Long The id corresponding to the currently selected item, or INVALID_ROW_ID if nothing is selected.

getSelectedItemPosition

Added in API level 1
open fun getSelectedItemPosition(): Int

Return the position of the currently selected item within the adapter's data set

Return
Int int Position (starting at 0), or INVALID_POSITION if there is nothing selected.

getSelectedView

Added in API level 1
abstract fun getSelectedView(): View!
Return
View! The view corresponding to the currently selected item, or null if nothing is selected

onProvideAutofillStructure

Added in API level 26
open fun onProvideAutofillStructure(
    structure: ViewStructure!,
    flags: Int
): Unit

Populates a ViewStructure to fullfil an autofill request.

The structure should contain at least the following properties:

It's also recommended to set the following properties - the more properties the structure has, the higher the chances of an android.service.autofill.AutofillService properly using the structure:

The default implementation of this method already sets most of these properties based on related View methods (for example, the autofill id is set using getAutofillId(), the autofill type set using getAutofillType(), etc.), and views in the standard Android widgets library also override it to set their relevant properties (for example, android.widget.TextView already sets the text properties), so it's recommended to only override this method (and call super.onProvideAutofillStructure()) when:

Note: The left and top values set in ViewStructure.setDimens(int, int, int, int, int, int) must be relative to the next ViewGroup.isImportantForAutofill() predecessor view included in the structure.

Views support the Autofill Framework mainly by:

  • Providing the metadata defining what the view means and how it can be autofilled.
  • Notifying the Android System when the view value changed by calling AutofillManager.notifyValueChanged(View).
  • Implementing the methods that autofill the view.

This method is responsible for the former; autofill(android.view.autofill.AutofillValue) is responsible for the latter.

It also sets the autofill options in the structure; when overridden, it should set it as well, either explicitly by calling ViewStructure.setAutofillOptions(CharSequence[]) or implicitly by calling super.onProvideAutofillStructure(structure, flags).

Parameters
structure ViewStructure!: fill in with structured view data for autofill purposes.
flags Int: optional flags. Value is either 0 or android.view.View#AUTOFILL_FLAG_INCLUDE_NOT_IMPORTANT_VIEWS

performItemClick

Added in API level 1
open fun performItemClick(
    view: View!,
    position: Int,
    id: Long
): Boolean

Call the OnItemClickListener, if it is defined. Performs all normal actions associated with clicking: reporting accessibility event, playing a sound, etc.

Parameters
view View!: The view within the AdapterView that was clicked.
position Int: The position of the view in the adapter.
id Long: The row id of the item that was clicked.
Return
Boolean True if there was an assigned OnItemClickListener that was called, false otherwise is returned.

removeAllViews

Added in API level 1
open fun removeAllViews(): Unit

This method is not supported and throws an UnsupportedOperationException when called.

Exceptions
java.lang.UnsupportedOperationException Every time this method is invoked.

removeView

Added in API level 1
open fun removeView(child: View!): Unit

This method is not supported and throws an UnsupportedOperationException when called.

Parameters
child View!: Ignored.
Exceptions
java.lang.UnsupportedOperationException Every time this method is invoked.

removeViewAt

Added in API level 1
open fun removeViewAt(index: Int): Unit

This method is not supported and throws an UnsupportedOperationException when called.

Parameters
index Int: Ignored.
Exceptions
java.lang.UnsupportedOperationException Every time this method is invoked.

setAdapter

Added in API level 1
abstract fun setAdapter(adapter: T): Unit

Sets the adapter that provides the data and the views to represent the data in this widget.

Parameters
adapter T: The adapter to use to create this view's content.

setEmptyView

Added in API level 1
open fun setEmptyView(emptyView: View!): Unit

Sets the view to show if the adapter is empty

setFocusable

Added in API level 26
open fun setFocusable(focusable: Int): Unit

Sets whether this view can receive focus.

Setting this to FOCUSABLE_AUTO tells the framework to determine focusability automatically based on the view's interactivity. This is the default.

Setting this to NOT_FOCUSABLE will ensure that this view is also not focusable in touch mode.

Parameters
focusable Int: Value is android.view.View#NOT_FOCUSABLE, android.view.View#FOCUSABLE, or android.view.View#FOCUSABLE_AUTO

setFocusableInTouchMode

Added in API level 1
open fun setFocusableInTouchMode(focusable: Boolean): Unit
Parameters
focusableInTouchMode If true, this view can receive the focus while in touch mode.

setOnClickListener

Added in API level 1
open fun setOnClickListener(l: View.OnClickListener?): Unit
Parameters
l View.OnClickListener?: The callback that will run This value may be null.

setOnItemClickListener

Added in API level 1
open fun setOnItemClickListener(listener: AdapterView.OnItemClickListener?): Unit

Register a callback to be invoked when an item in this AdapterView has been clicked.

Parameters
listener AdapterView.OnItemClickListener?: The callback that will be invoked. This value may be null.

setOnItemLongClickListener

Added in API level 1
open fun setOnItemLongClickListener(listener: AdapterView.OnItemLongClickListener!): Unit

Register a callback to be invoked when an item in this AdapterView has been clicked and held

Parameters
listener AdapterView.OnItemLongClickListener!: The callback that will run

setOnItemSelectedListener

Added in API level 1
open fun setOnItemSelectedListener(listener: AdapterView.OnItemSelectedListener?): Unit

Register a callback to be invoked when an item in this AdapterView has been selected.

Parameters
listener AdapterView.OnItemSelectedListener?: The callback that will run This value may be null.

setSelection

Added in API level 1
abstract fun setSelection(position: Int): Unit

Sets the currently selected item. To support accessibility subclasses that override this method must invoke the overridden super method first.

Parameters
position Int: Index (starting at 0) of the data item to be selected.

Protected methods

canAnimate

Added in API level 1
protected open fun canAnimate(): Boolean
Return
Boolean true if the children can be animated, false otherwise

dispatchRestoreInstanceState

Added in API level 1
protected open fun dispatchRestoreInstanceState(container: SparseArray<Parcelable!>!): Unit

Override to prevent thawing of any views created by the adapter.

Parameters
container SparseArray<Parcelable!>!: The SparseArray which holds previously saved state.

dispatchSaveInstanceState

Added in API level 1
protected open fun dispatchSaveInstanceState(container: SparseArray<Parcelable!>!): Unit

Override to prevent freezing of any views created by the adapter.

Parameters
container SparseArray<Parcelable!>!: The SparseArray in which to save the view's state.

onDetachedFromWindow

Added in API level 1
protected open fun onDetachedFromWindow(): Unit

onLayout

Added in API level 1
protected open fun onLayout(
    changed: Boolean,
    left: Int,
    top: Int,
    right: Int,
    bottom: Int
): Unit
Parameters
changed Boolean: This is a new size or position for this view
left Int: Left position, relative to parent
top Int: Top position, relative to parent
right Int: Right position, relative to parent
bottom Int: Bottom position, relative to parent