Class AdapterView<T extends Adapter>

Type Parameters:
T - the adapter type
All Implemented Interfaces:
Drawable.Callback, ViewManager, ViewParent
Direct Known Subclasses:
AbsListView, AbsSpinner

public abstract class AdapterView<T extends Adapter> extends ViewGroup
An AdapterView is a view whose children are determined by an Adapter.
  • Field Details

    • ITEM_VIEW_TYPE_IGNORE

      public static final int ITEM_VIEW_TYPE_IGNORE
      The item view type returned by Adapter.getItemViewType(int) when the adapter does not want the item's view recycled.
      See Also:
    • INVALID_POSITION

      public static final int INVALID_POSITION
      Represents an invalid position. All valid positions are in the range 0 to 1 less than the number of items in the current adapter.
      See Also:
    • INVALID_ROW_ID

      public static final long INVALID_ROW_ID
      Represents an empty or invalid row id
      See Also:
  • Constructor Details

    • AdapterView

      public AdapterView(Context context)
  • Method Details

    • setOnItemClickListener

      public void setOnItemClickListener(@Nullable AdapterView.OnItemClickListener listener)
      Register a callback to be invoked when an item in this AdapterView has been clicked.
      Parameters:
      listener - The callback that will be invoked.
    • getOnItemClickListener

      @Nullable public final AdapterView.OnItemClickListener getOnItemClickListener()
      Returns:
      The callback to be invoked with an item in this AdapterView has been clicked, or null if no callback has been set.
    • performItemClick

      public boolean performItemClick(View view, int position, long id)
      Call the OnItemClickListener, if it is defined. Performs all normal actions associated with clicking: reporting accessibility event, playing a sound, etc.
      Parameters:
      view - The view within the AdapterView that was clicked.
      position - The position of the view in the adapter.
      id - The row id of the item that was clicked.
      Returns:
      True if there was an assigned OnItemClickListener that was called, false otherwise is returned.
    • setOnItemLongClickListener

      public void setOnItemLongClickListener(AdapterView.OnItemLongClickListener listener)
      Register a callback to be invoked when an item in this AdapterView has been clicked and held
      Parameters:
      listener - The callback that will run
    • getOnItemLongClickListener

      public final AdapterView.OnItemLongClickListener getOnItemLongClickListener()
      Returns:
      The callback to be invoked with an item in this AdapterView has been clicked and held, or null if no callback has been set.
    • setOnItemSelectedListener

      public void setOnItemSelectedListener(@Nullable AdapterView.OnItemSelectedListener listener)
      Register a callback to be invoked when an item in this AdapterView has been selected.
      Parameters:
      listener - The callback that will run
    • getOnItemSelectedListener

      @Nullable public final AdapterView.OnItemSelectedListener getOnItemSelectedListener()
    • getAdapter

      public abstract T getAdapter()
      Returns the adapter currently associated with this widget.
      Returns:
      The adapter used to provide this view's content.
    • setAdapter

      public abstract void setAdapter(T adapter)
      Sets the adapter that provides the data and the views to represent the data in this widget.
      Parameters:
      adapter - The adapter to use to create this view's content.
    • addView

      public void addView(@Nonnull View child)
      This method is not supported and throws an UnsupportedOperationException when called.
      Overrides:
      addView in class ViewGroup
      Parameters:
      child - Ignored.
      Throws:
      UnsupportedOperationException - Every time this method is invoked.
      See Also:
    • addView

      public void addView(@Nonnull View child, int index)
      This method is not supported and throws an UnsupportedOperationException when called.
      Overrides:
      addView in class ViewGroup
      Parameters:
      child - Ignored.
      index - Ignored.
      Throws:
      UnsupportedOperationException - Every time this method is invoked.
      See Also:
    • addView

      public void addView(@Nonnull View child, @Nonnull ViewGroup.LayoutParams params)
      This method is not supported and throws an UnsupportedOperationException when called.
      Specified by:
      addView in interface ViewManager
      Overrides:
      addView in class ViewGroup
      Parameters:
      child - Ignored.
      params - Ignored.
      Throws:
      UnsupportedOperationException - Every time this method is invoked.
    • addView

      public void addView(@Nonnull View child, int index, @Nonnull ViewGroup.LayoutParams params)
      This method is not supported and throws an UnsupportedOperationException when called.
      Overrides:
      addView in class ViewGroup
      Parameters:
      child - Ignored.
      index - Ignored.
      params - Ignored.
      Throws:
      UnsupportedOperationException - Every time this method is invoked.
    • removeView

      public void removeView(@Nonnull View child)
      This method is not supported and throws an UnsupportedOperationException when called.
      Specified by:
      removeView in interface ViewManager
      Overrides:
      removeView in class ViewGroup
      Parameters:
      child - Ignored.
      Throws:
      UnsupportedOperationException - Every time this method is invoked.
    • removeViewAt

      public void removeViewAt(int index)
      This method is not supported and throws an UnsupportedOperationException when called.
      Overrides:
      removeViewAt in class ViewGroup
      Parameters:
      index - Ignored.
      Throws:
      UnsupportedOperationException - Every time this method is invoked.
    • removeAllViews

      public void removeAllViews()
      This method is not supported and throws an UnsupportedOperationException when called.
      Overrides:
      removeAllViews in class ViewGroup
      Throws:
      UnsupportedOperationException - Every time this method is invoked.
    • onLayout

      protected void onLayout(boolean changed, int left, int top, int right, int bottom)
      Description copied from class: View
      Called from View.layout(int, int, int, int) when this view should assign a size and position to each of its children.

      Derived classes with children should override this method and call layout on each of their children.

      Specified by:
      onLayout in class ViewGroup
      Parameters:
      changed - This is a new size or position for this view
      left - Left position, relative to parent
      top - Top position, relative to parent
      right - Right position, relative to parent
      bottom - Bottom position, relative to parent
    • getSelectedItemPosition

      public int getSelectedItemPosition()
      Return the position of the currently selected item within the adapter's data set
      Returns:
      int Position (starting at 0), or INVALID_POSITION if there is nothing selected.
    • getSelectedItemId

      public long getSelectedItemId()
      Returns:
      The id corresponding to the currently selected item, or INVALID_ROW_ID if nothing is selected.
    • getSelectedView

      @Nullable public abstract View getSelectedView()
      Returns:
      The view corresponding to the currently selected item, or null if nothing is selected
    • getSelectedItem

      @Nullable public Object getSelectedItem()
      Returns:
      The data corresponding to the currently selected item, or null if there is nothing selected.
    • getCount

      public int getCount()
      Returns:
      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.)
    • getPositionForView

      public int getPositionForView(View view)
      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 - an adapter item, or a descendant of an adapter item. This must be visible in this AdapterView at the time of the call.
      Returns:
      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)
    • getFirstVisiblePosition

      public int getFirstVisiblePosition()
      Returns the position within the adapter's data set for the first item displayed on screen.
      Returns:
      The position within the adapter's data set
    • getLastVisiblePosition

      public int getLastVisiblePosition()
      Returns the position within the adapter's data set for the last item displayed on screen.
      Returns:
      The position within the adapter's data set
    • setSelection

      public abstract void setSelection(int position)
      Sets the currently selected item. To support accessibility subclasses that override this method must invoke the overridden super method first.
      Parameters:
      position - Index (starting at 0) of the data item to be selected.
    • setEmptyView

      public void setEmptyView(View emptyView)
      Sets the view to show if the adapter is empty
    • getEmptyView

      public View getEmptyView()
      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.
      Returns:
      The view to show if the adapter is empty.
    • setFocusable

      public void setFocusable(int focusable)
      Description copied from class: View
      Sets whether this view can receive focus.

      Setting this to View.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.

      Overrides:
      setFocusable in class View
      Parameters:
      focusable - One of View.NOT_FOCUSABLE, View.FOCUSABLE, or View.FOCUSABLE_AUTO.
      See Also:
    • setFocusableInTouchMode

      public void setFocusableInTouchMode(boolean focusable)
      Description copied from class: View
      Set whether this view can receive focus while in touch mode.

      Setting this to true will also ensure that this view is focusable.

      Overrides:
      setFocusableInTouchMode in class View
      Parameters:
      focusable - If true, this view can receive the focus while in touch mode.
      See Also:
    • getItemAtPosition

      @Nullable public Object getItemAtPosition(int position)
      Gets the data associated with the specified position in the list.
      Parameters:
      position - Which data to get
      Returns:
      The data associated with the specified position in the list
    • getItemIdAtPosition

      public long getItemIdAtPosition(int position)
    • setOnClickListener

      public void setOnClickListener(@Nullable View.OnClickListener l)
      Description copied from class: View
      Register a callback to be invoked when this view is clicked. If this view is not clickable, it becomes clickable.
      Overrides:
      setOnClickListener in class View
      Parameters:
      l - The callback that will run
      See Also:
    • onDetachedFromWindow

      protected void onDetachedFromWindow()
      Description copied from class: View
      This is called when the view is detached from a window. At this point it no longer has a surface for drawing.
      Overrides:
      onDetachedFromWindow in class View
      See Also: