public class PreferenceGroupAdapter extends RecyclerView.Adapter<PreferenceViewHolder> implements PreferenceGroup.PreferencePositionCallback
Preference
objects contained in the
associated PreferenceGroup
.Constructor and Description |
---|
PreferenceGroupAdapter(PreferenceGroup preferenceGroup) |
Modifier and Type | Method and Description |
---|---|
Preference |
getItem(int position) |
int |
getItemCount()
Returns the total number of items in the data set held by the adapter.
|
long |
getItemId(int position)
Return the stable ID for the item at
position . |
int |
getItemViewType(int position)
Return the view type of the item at
position for the purposes
of view recycling. |
int |
getPreferenceAdapterPosition(Preference preference)
Return the adapter position of the specified
Preference object |
int |
getPreferenceAdapterPosition(String key)
Return the adapter position of the first
Preference with the specified key |
void |
onBindViewHolder(PreferenceViewHolder holder,
int position)
Called by RecyclerView to display the data at the specified position.
|
PreferenceViewHolder |
onCreateViewHolder(ViewGroup parent,
int viewType)
Called when RecyclerView needs a new
RecyclerView.ViewHolder of the given type to represent
an item. |
void |
onPreferenceChange(Preference preference)
Called when this Preference has changed.
|
void |
onPreferenceHierarchyChange(Preference preference)
Called when this group has added/removed
Preference (s). |
void |
onPreferenceVisibilityChange(Preference preference)
Called when this preference has changed its visibility.
|
bindViewHolder, createViewHolder, hasObservers, hasStableIds, notifyDataSetChanged, notifyItemChanged, notifyItemChanged, notifyItemInserted, notifyItemMoved, notifyItemRangeChanged, notifyItemRangeChanged, notifyItemRangeInserted, notifyItemRangeRemoved, notifyItemRemoved, onAttachedToRecyclerView, onBindViewHolder, onDetachedFromRecyclerView, onFailedToRecycleView, onViewAttachedToWindow, onViewDetachedFromWindow, onViewRecycled, registerAdapterDataObserver, setHasStableIds, unregisterAdapterDataObserver
public PreferenceGroupAdapter(PreferenceGroup preferenceGroup)
public int getItemCount()
RecyclerView.Adapter
getItemCount
in class RecyclerView.Adapter<PreferenceViewHolder>
public Preference getItem(int position)
public long getItemId(int position)
RecyclerView.Adapter
position
. If RecyclerView.Adapter.hasStableIds()
would return false this method should return RecyclerView.NO_ID
. The default implementation
of this method returns RecyclerView.NO_ID
.getItemId
in class RecyclerView.Adapter<PreferenceViewHolder>
position
- Adapter position to querypublic void onPreferenceChange(Preference preference)
preference
- This preference.public void onPreferenceHierarchyChange(Preference preference)
Preference
(s).preference
- This Preference.public void onPreferenceVisibilityChange(Preference preference)
preference
- This Preference.public int getItemViewType(int position)
RecyclerView.Adapter
position
for the purposes
of view recycling.
The default implementation of this method returns 0, making the assumption of a single view type for the adapter. Unlike ListView adapters, types need not be contiguous. Consider using id resources to uniquely identify item view types.
getItemViewType
in class RecyclerView.Adapter<PreferenceViewHolder>
position
- position to queryposition
. Type codes need not be contiguous.public PreferenceViewHolder onCreateViewHolder(ViewGroup parent, int viewType)
RecyclerView.Adapter
RecyclerView.ViewHolder
of the given type to represent
an item.
This new ViewHolder should be constructed with a new View that can represent the items of the given type. You can either create a new View manually or inflate it from an XML layout file.
The new ViewHolder will be used to display items of the adapter using
#onBindViewHolder(ViewHolder, int, List)
. Since it will be re-used to display
different items in the data set, it is a good idea to cache references to sub views of
the View to avoid unnecessary View.findViewById(int)
calls.
onCreateViewHolder
in class RecyclerView.Adapter<PreferenceViewHolder>
parent
- The ViewGroup into which the new View will be added after it is bound to
an adapter position.viewType
- The view type of the new View.RecyclerView.Adapter.getItemViewType(int)
,
#onBindViewHolder(ViewHolder, int)
public void onBindViewHolder(PreferenceViewHolder holder, int position)
RecyclerView.Adapter
RecyclerView.ViewHolder.itemView
to reflect the item at the given
position.
Note that unlike ListView
, RecyclerView will not call this method
again if the position of the item changes in the data set unless the item itself is
invalidated or the new position cannot be determined. For this reason, you should only
use the position
parameter while acquiring the related data item inside
this method and should not keep a copy of it. If you need the position of an item later
on (e.g. in a click listener), use RecyclerView.ViewHolder.getAdapterPosition()
which will
have the updated adapter position.
Override #onBindViewHolder(ViewHolder, int, List)
instead if Adapter can
handle efficient partial bind.
onBindViewHolder
in class RecyclerView.Adapter<PreferenceViewHolder>
holder
- The ViewHolder which should be updated to represent the contents of the
item at the given position in the data set.position
- The position of the item within the adapter's data set.public int getPreferenceAdapterPosition(String key)
PreferenceGroup.PreferencePositionCallback
Preference
with the specified keygetPreferenceAdapterPosition
in interface PreferenceGroup.PreferencePositionCallback
key
- Key of Preference
to findPreference
or
RecyclerView.NO_POSITION
if not foundpublic int getPreferenceAdapterPosition(Preference preference)
PreferenceGroup.PreferencePositionCallback
Preference
objectgetPreferenceAdapterPosition
in interface PreferenceGroup.PreferencePositionCallback
preference
- Preference
object to findPreference
or
RecyclerView.NO_POSITION
if not found