Item - Type of the item presented within a data set of a subclass of this BaseSpinnerAdapter.VH - Type of the view holder used within a subclass of this BaseSpinnerAdapter.DVH - Type of the drop down view holder used within a subclass of this BaseSpinnerAdapter.public abstract class BaseSpinnerAdapter<Item,VH,DVH> extends BaseAdapter<Item,VH>
BaseAdapter implementation that may be used to provide optimized adapter also for
Spinner widget. This "spinner based" adapter also supports API to
store current selected item and its corresponding position. The position of the selected item is
stored whenever getView(int, View, ViewGroup) is called. The selected item position may
be obtained via getSelectedItemPosition().mContext, mLayoutInflater, mResourcesNO_ID, NO_POSITIONIGNORE_ITEM_VIEW_TYPE, NO_SELECTION| Constructor and Description |
|---|
BaseSpinnerAdapter(Context context)
Creates a new instance of BaseSpinnerAdapter within the given context.
|
| Modifier and Type | Method and Description |
|---|---|
View |
getDropDownView(int position,
View convertView,
ViewGroup parent)
Performs optimized algorithm for this method using the Holder pattern.
|
Item |
getSelectedItem()
Returns the item model of this adapter for the current selected position.
|
int |
getSelectedItemPosition()
Returns the position of the currently selected item.
|
View |
getView(int position,
View convertView,
ViewGroup parent) |
protected void |
onBindDropDownViewHolder(DVH viewHolder,
int position)
Invoked to configure and bind a drop down view of an item from the current data set at the
specified position.
|
protected void |
onBindViewHolder(VH viewHolder,
int position)
This implementation by default invokes
#onUpdateViewHolder(Object, Item, int) with
item at the current selected position. |
protected View |
onCreateDropDownView(ViewGroup parent,
int position)
Invoked to create a drop down view for an item from the current data set at the specified
position.
|
protected DVH |
onCreateDropDownViewHolder(View itemView,
int position)
Invoked to create a view holder for a drop down view of an item from the current data set at
the specified position.
|
protected abstract void |
onUpdateViewHolder(DVH viewHolder,
Item item,
int position)
Invoked to update views of the given viewHolder with data of the given cursor.
|
currentViewType, getCount, getItemId, hasStableIds, inflate, notifyDataSetActionSelected, notifyDataSetChanged, notifyDataSetInvalidated, onCreateView, onCreateViewHolder, onDataSetActionSelected, registerOnDataChangeListener, registerOnDataSetActionListener, registerOnDataSetListener, restoreInstanceState, saveInstanceState, unregisterOnDataChangeListener, unregisterOnDataSetActionListener, unregisterOnDataSetListenerareAllItemsEnabled, getItemViewType, getViewTypeCount, isEmpty, isEnabled, registerDataSetObserver, unregisterDataSetObserverclone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitisEnabledgetItem, getItemCount, hasItemAt, isEmpty@NonNull public Item getSelectedItem()
Adapter.getItem(int) for the current selected position.getSelectedItemPosition()public int getSelectedItemPosition()
DataSet.NO_POSITION if this adapter does not have its data set specified.getSelectedItem()public View getDropDownView(int position, @Nullable View convertView, @NonNull ViewGroup parent)
getDropDownView in interface SpinnerAdaptergetDropDownView in class BaseAdapter@NonNull protected View onCreateDropDownView(@NonNull ViewGroup parent, int position)
This is invoked only if convertView for the specified position in
getDropDownView(int, View, ViewGroup) was null.
parent - A parent view, to resolve correct layout params for the newly creating view.position - Position of the item from the current data set for which should be a new drop
down view created.BaseAdapter.inflate(int, ViewGroup)@Nullable protected DVH onCreateDropDownViewHolder(@NonNull View itemView, int position)
This is invoked only if convertView for the specified position in
getDropDownView(int, View, ViewGroup) was null, so drop down view along with
its corresponding holder need to be created.
itemView - The same view as obtained from onCreateDropDownView(ViewGroup, int)
for the specified position.position - Position of the item from the current data set for which should be a new drop
down view holder created.null if holder for the drop
down view is not required.protected void onBindViewHolder(@NonNull VH viewHolder, int position)
#onUpdateViewHolder(Object, Item, int) with
item at the current selected position.onBindViewHolder in class BaseAdapter<Item,VH>viewHolder - The same holder as provided by BaseAdapter.onCreateViewHolder(View, int) for
the specified position or converted view as holder as described above.position - Position of the item from the current data set of which view to bind with data.getSelectedItemPosition()protected void onBindDropDownViewHolder(@NonNull DVH viewHolder, int position)
getDropDownView(int, View, ViewGroup)
is called.
Note, that if onCreateDropDownViewHolder(View, int) returns null for
the specified position here passed viewHolder will be the view created
by onCreateDropDownView(ViewGroup, int) for the specified position or just recycled
view for that position. This approach may be used when a view hierarchy of a specific item is
represented by single custom view, where such view represents a holder for all its child views.
viewHolder - The same holder as provided by onCreateDropDownViewHolder(View, int)
for the specified position or converted view as holder as described above.position - Position of the item from the current data set of which view to bind with data.protected abstract void onUpdateViewHolder(@NonNull DVH viewHolder, @NonNull Item item, int position)
viewHolder - The view holder passed either to onBindViewHolder(Object, int) or
to onBindDropDownViewHolder(Object, int).item - Item from the adapter's data set at the specified position.position - Position of the item from the current data set of which view holder to update.