public class SettingHeadersAdapter
extends android.widget.BaseAdapter
BaseAdapter implementation used to provide data set of Items for adapter
view that displays a list of setting preferences in the context of SettingsBaseActivity.
This adapter uses the following view types to provide views for its data set of items:
VIEW_TYPE_CATEGORY - view for the category header that has no fragment nor intent associated,VIEW_TYPE_CATEGORY_DIVIDER - view for divider between category headers,VIEW_TYPE_HEADER - view for the selectable header.
Data set of items with associated headers may be supplied via SettingHeadersAdapter(Context, List)
constructor or changed via changeHeaders(List). A specific item at a desired position may
be obtained via getItem(int) and its associated header via getItem(int).getHeader().
| Modifier and Type | Class and Description |
|---|---|
static class |
SettingHeadersAdapter.CategoryDividerHolder
A
SettingHeadersAdapter.ViewHolder implementation for category divider view of SettingHeadersAdapter. |
static class |
SettingHeadersAdapter.CategoryHolder
A
SettingHeadersAdapter.ViewHolder implementation for category item view of SettingHeadersAdapter. |
static class |
SettingHeadersAdapter.HeaderHolder
A
SettingHeadersAdapter.ViewHolder implementation for header item view of SettingHeadersAdapter. |
static class |
SettingHeadersAdapter.Item
Item class represents a data model for
SettingHeadersAdapter. |
static class |
SettingHeadersAdapter.ViewHolder
Base class for view holder implementations used in
SettingHeadersAdapter. |
| Modifier and Type | Field and Description |
|---|---|
static long |
NO_ID
Constant that identifies invalid/unspecified id.
|
static int |
NO_POSITION
Constant that identifies invalid/unspecified position attached to a specified holder.
|
static int |
VIEW_TYPE_CATEGORY
View type for the category item.
|
static int |
VIEW_TYPE_CATEGORY_DIVIDER
View type for the category divider.
|
static int |
VIEW_TYPE_HEADER
View type for the header item.
|
| Constructor and Description |
|---|
SettingHeadersAdapter(android.content.Context context)
Creates a new instance of SettingHeadersAdapter with empty data set.
|
SettingHeadersAdapter(android.content.Context context,
List<android.preference.PreferenceActivity.Header> headers)
Creates a new instance of SettingHeadersAdapter with the initial data set of headers.
|
SettingHeadersAdapter(android.content.Context context,
android.preference.PreferenceActivity.Header[] headers)
Same as
SettingHeadersAdapter(Context, List) for array of headers. |
| Modifier and Type | Method and Description |
|---|---|
void |
changeHeaders(List<android.preference.PreferenceActivity.Header> headers)
Same as
swapHeaders(List) where the old headers are ignored. |
int |
getCount() |
SettingHeadersAdapter.Item |
getItem(int position) |
long |
getItemId(int position) |
int |
getItemViewType(int position) |
android.view.View |
getView(int position,
android.view.View convertView,
android.view.ViewGroup parent) |
int |
getViewTypeCount() |
boolean |
hasItemAt(int position)
Returns a boolean flag indicating whether this data set has item that can provide data for the
specified position or not.
|
boolean |
hasStableIds() |
android.view.View |
inflateView(int resource,
android.view.ViewGroup parent)
Inflates a new view hierarchy from the given xml resource.
|
boolean |
isCategoryAt(int position)
Checks whether item at the specified position is a category.
|
boolean |
isCategoryDividerAt(int position)
Checks whether item at the specified position is a category divider.
|
boolean |
isEnabled(int position) |
boolean |
isHeaderAt(int position)
Checks whether item at the specified position is a header.
|
protected void |
onBindViewHolder(SettingHeadersAdapter.ViewHolder viewHolder,
int position)
Invoked from
getView(int, View, ViewGroup) in order to perform binding of the given
viewHolder with data of the item from this adapter's data set at the specified
position. |
protected SettingHeadersAdapter.ViewHolder |
onCreateViewHolder(android.view.ViewGroup parent,
int viewType)
Invoked from
getView(int, View, ViewGroup) in order to create a view holder along
with its corresponding item view for the specified viewType. |
void |
setUseVectorIcons(boolean useVectorIcons)
Sets a boolean flag indicating whether this adapter should treat icon parameter specified
via
PreferenceActivity.Header#iconRes as resource of vector drawable or as resource
of standard drawable. |
List<android.preference.PreferenceActivity.Header> |
swapHeaders(List<android.preference.PreferenceActivity.Header> headers)
Swaps the current data set of this adapter for the given headers.
|
public static final int NO_POSITION
public static final long NO_ID
public static final int VIEW_TYPE_CATEGORY
public static final int VIEW_TYPE_CATEGORY_DIVIDER
public static final int VIEW_TYPE_HEADER
This is only view type that is by default enabled by this adapter.
isEnabled(int),
Constant Field Valuespublic SettingHeadersAdapter(@NonNull
android.content.Context context)
SettingHeadersAdapter(Context, List)public SettingHeadersAdapter(@NonNull
android.content.Context context,
@NonNull
android.preference.PreferenceActivity.Header[] headers)
SettingHeadersAdapter(Context, List) for array of headers.public SettingHeadersAdapter(@NonNull
android.content.Context context,
@NonNull
List<android.preference.PreferenceActivity.Header> headers)
context - Context in which will be the new adapter used.headers - Initial data set of headers.changeHeaders(List)public void setUseVectorIcons(boolean useVectorIcons)
PreferenceActivity.Header#iconRes as resource of vector drawable or as resource
of standard drawable.useVectorIcons - True to apply icon resources of items as vector drawables,
false as standard drawables.public void changeHeaders(@Nullable
List<android.preference.PreferenceActivity.Header> headers)
swapHeaders(List) where the old headers are ignored.@Nullable public List<android.preference.PreferenceActivity.Header> swapHeaders(@Nullable List<android.preference.PreferenceActivity.Header> headers)
Note, that as this adapter uses multiple view types to present its data set, the
specified headers are transformed into data set of Items. A specific item at a
desired position via getItem(int). Header associated
with an item at a specific position may be obtained via getItem(int).getHeader().
headers - The headers for which to create a new data set. May be null to clear
the current data set.changeHeaders(List)public int getCount()
public boolean hasItemAt(int position)
position - The position of item to check.True if getItem(int) can be called 'safely', false otherwise.@NonNull public SettingHeadersAdapter.Item getItem(int position)
public boolean hasStableIds()
hasStableIds in interface android.widget.AdapterhasStableIds in class android.widget.BaseAdapterpublic long getItemId(int position)
public int getViewTypeCount()
getViewTypeCount in interface android.widget.AdaptergetViewTypeCount in class android.widget.BaseAdapterpublic int getItemViewType(int position)
getItemViewType in interface android.widget.AdaptergetItemViewType in class android.widget.BaseAdapterpublic boolean isEnabled(int position)
isEnabled in interface android.widget.ListAdapterisEnabled in class android.widget.BaseAdapterTrue if item at the position is header, false otherwise.isHeaderAt(int)public boolean isHeaderAt(int position)
position - The position of item to check.True if item at the position is header, false otherwise.public boolean isCategoryAt(int position)
position - The position of item to check.True if item at the position is category, false otherwise.isHeaderAt(int),
isCategoryDividerAt(int)public boolean isCategoryDividerAt(int position)
position - The position of item to check.True if item at the position is category divider, false otherwise.isCategoryAt(int)public android.view.View getView(int position,
@Nullable
android.view.View convertView,
@NonNull
android.view.ViewGroup parent)
@NonNull protected SettingHeadersAdapter.ViewHolder onCreateViewHolder(@NonNull android.view.ViewGroup parent, int viewType)
getView(int, View, ViewGroup) in order to create a view holder along
with its corresponding item view for the specified viewType.parent - A parent view, to resolve correct layout params in case when the item view
will be inflated from an Xml layout.viewType - Type of the item view to be created with the holder. This is the same identifier
as obtained via getItemViewType(int) for the position passed to
getView(int, View, ViewGroup) method.inflateView(int, ViewGroup)@NonNull
public android.view.View inflateView(@LayoutRes
int resource,
@Nullable
android.view.ViewGroup parent)
resource - Resource id of a view to inflateView.parent - A parent view, to resolve correct layout params for the newly creating view.LayoutInflater.inflate(int, ViewGroup)protected void onBindViewHolder(@NonNull
SettingHeadersAdapter.ViewHolder viewHolder,
int position)
getView(int, View, ViewGroup) in order to perform binding of the given
viewHolder with data of the item from this adapter's data set at the specified
position.viewHolder - The view holder created via onCreateViewHolder(ViewGroup, int)
with its corresponding item view to be bound with data.position - Position of the item from the current data set of which data should be bound
to the view holder.