public class SettingHeadersAdapter
extends <any>
SimpleAdapter 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). The current data set of transformed items
may be obtained via #getItems(). 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
ViewHolder implementation for category divider view of SettingHeadersAdapter. |
static class |
SettingHeadersAdapter.CategoryHolder
A
ViewHolder implementation for category item view of SettingHeadersAdapter. |
static class |
SettingHeadersAdapter.HeaderHolder
A
ViewHolder implementation for header item view of SettingHeadersAdapter. |
static class |
SettingHeadersAdapter.Item
Item class represents a data model for
SettingHeadersAdapter. |
| Modifier and Type | Field and Description |
|---|---|
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(Context context)
Creates a new instance of SettingHeadersAdapter with empty data set.
|
SettingHeadersAdapter(Context context,
List<PreferenceActivity.Header> headers)
Creates a new instance of SettingHeadersAdapter with the initial data set of headers.
|
SettingHeadersAdapter(Context context,
PreferenceActivity.Header[] headers)
Same as
SettingHeadersAdapter(Context, List) for array of headers. |
| Modifier and Type | Method and Description |
|---|---|
void |
changeHeaders(List<PreferenceActivity.Header> headers)
Changes the current data set of this adapter for the given headers.
|
void |
changeItems(List<SettingHeadersAdapter.Item> items) |
int |
getItemViewType(int position) |
int |
getViewTypeCount() |
boolean |
hasStableIds() |
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(ViewHolder viewHolder,
int position) |
protected View |
onCreateView(ViewGroup parent,
int position) |
protected ViewHolder |
onCreateViewHolder(View itemView,
int position) |
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<PreferenceActivity.Header> |
swapHeaders(List<PreferenceActivity.Header> headers)
Like
changeHeaders(List), but this will also return the old headers supplied to this
adapter before (if any). |
List<SettingHeadersAdapter.Item> |
swapItems(List<SettingHeadersAdapter.Item> items) |
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 Context context)
SimpleAdapter#SimpleAdapter(Context),
SettingHeadersAdapter(Context, List)public SettingHeadersAdapter(@NonNull Context context, @NonNull PreferenceActivity.Header[] headers)
SettingHeadersAdapter(Context, List) for array of headers.public SettingHeadersAdapter(@NonNull Context context, @NonNull List<PreferenceActivity.Header> headers)
context - Context in which will be the new adapter used.headers - Initial data set of headers.changeHeaders(List),
#getItems()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.@Nullable public final List<SettingHeadersAdapter.Item> swapItems(@Nullable List<SettingHeadersAdapter.Item> items)
UnsupportedOperationException - Use swapHeaders(List) instead.@Nullable public List<PreferenceActivity.Header> swapHeaders(@Nullable List<PreferenceActivity.Header> headers)
changeHeaders(List), but this will also return the old headers supplied to this
adapter before (if any).public final void changeItems(@Nullable List<SettingHeadersAdapter.Item> items)
UnsupportedOperationException - Use changeHeaders(List) instead.public void changeHeaders(@Nullable List<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. The items data set may be obtained
via #getItems() or 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.public boolean hasStableIds()
public int getViewTypeCount()
public int getItemViewType(int position)
public boolean isEnabled(int position)
True 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)@Nullable protected ViewHolder onCreateViewHolder(@NonNull View itemView, int position)
protected void onBindViewHolder(@NonNull ViewHolder viewHolder, int position)