Package eltos.simpledialogfragment.list
Class AdvancedAdapter<T>
java.lang.Object
android.widget.BaseAdapter
eltos.simpledialogfragment.list.AdvancedAdapter<T>
- All Implemented Interfaces:
android.widget.Adapter
,android.widget.Filterable
,android.widget.ListAdapter
,android.widget.SpinnerAdapter
- Direct Known Subclasses:
AdvancedSectionAdapter
,SimpleColorDialog.ColorAdapter
public abstract class AdvancedAdapter<T>
extends android.widget.BaseAdapter
implements android.widget.Filterable
Created by eltos on 04.12.2016.
This adapter keeps track of checked items even if they are currently not visible
due to filtering.
When extending this class, note the following:
- Set the underlying data set via
setData(T[])
or setDataAndIds(T[], long[])
- Overwrite getView(int, android.view.View, android.view.ViewGroup)
. You can either return with the super-call, that will
automatically care for the checked state if the View is an instance of Checkable
or set checked state yourself by using isItemChecked(int)
In your activity refer to the isItemChecked(int)
and other functions to get
checked items rather than using the functions of the ListView!-
Nested Class Summary
Modifier and TypeClassDescriptionclass
An advanced filter where only theAdvancedAdapter.AdvancedFilter.matches(T, java.lang.CharSequence)
method needs to be overwrittenstatic interface
-
Field Summary
Modifier and TypeFieldDescriptionstatic final int
static final int
static final int
Fields inherited from interface android.widget.Adapter
IGNORE_ITEM_VIEW_TYPE, NO_SELECTION
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionprotected void
int
int
getCount()
getData()
Get the data maintained by this adapterOverwrite this method to return your AdvancedFilter heregetItem
(int filteredPosition) long
getItemId
(int filteredPosition) android.view.View
getView
(int position, android.view.View convertView, android.view.ViewGroup parent) protected android.text.Spannable
Highlights everything that matched the current filter (if any) in textprotected android.text.Spannable
Highlights everything that matched the current filter (if any) in textboolean
isItemChecked
(int filteredPosition) void
void
setAllItemsChecked
(boolean checked) void
setChoiceMode
(int choiceMode) Defines the choice behavior for the list.void
Set this adapters datavoid
setData
(ArrayList<? extends T> list, AdvancedAdapter.ItemIdentifier<T> identifier) Set this adapters data and idsvoid
Set this adapters datavoid
setData
(T[] list, AdvancedAdapter.ItemIdentifier<T> identifier) Set this adapters data and idsvoid
setDataAndIds
(ArrayList<androidx.core.util.Pair<T, Long>> list) void
setDataAndIds
(T[] list, long[] ids) void
setItemChecked
(int filteredPosition, boolean checked) void
setItemChecked
(long id, boolean checked) void
setItemsCheckedFromIds
(long[] checkedItemIds) void
setItemsCheckedFromIds
(ArrayList<Long> checkedItemIds) void
toggleChecked
(int filteredPosition) Methods inherited from class android.widget.BaseAdapter
areAllItemsEnabled, getAutofillOptions, getDropDownView, getItemViewType, getViewTypeCount, hasStableIds, isEmpty, isEnabled, notifyDataSetInvalidated, registerDataSetObserver, setAutofillOptions, unregisterDataSetObserver
-
Field Details
-
CHOICE_MODE_NONE
public static final int CHOICE_MODE_NONE- See Also:
-
CHOICE_MODE_SINGLE
public static final int CHOICE_MODE_SINGLE- See Also:
-
CHOICE_MODE_MULTIPLE
public static final int CHOICE_MODE_MULTIPLE- See Also:
-
-
Constructor Details
-
AdvancedAdapter
public AdvancedAdapter()
-
-
Method Details
-
setData
Set this adapters data- Parameters:
list
- a list of objects to be maintained by this adapter
-
setData
Set this adapters data- Parameters:
list
- an array-list of objects to be maintained by this adapter
-
setData
Set this adapters data and ids- Parameters:
list
- a list of objects to be maintained by this adapteridentifier
- an Identifier returning a unique id for every item
-
setData
Set this adapters data and ids- Parameters:
list
- an array-list of objects to be maintained by this adapteridentifier
- an Identifier returning a unique id for every item
-
setDataAndIds
-
setDataAndIds
-
getData
Get the data maintained by this adapter- Returns:
- an array-list of the data
-
getFilter
Overwrite this method to return your AdvancedFilter here- Specified by:
getFilter
in interfaceandroid.widget.Filterable
- Returns:
- an instance of AdvancedFilter for filtering data
-
setChoiceMode
public void setChoiceMode(int choiceMode) Defines the choice behavior for the list. By default, lists do not have any choice behavior (CHOICE_MODE_NONE
). By setting the choiceMode toCHOICE_MODE_SINGLE
, the list allows up to one item to be checked UsingCHOICE_MODE_MULTIPLE
, any number of items may be checked.- Parameters:
choiceMode
- One ofCHOICE_MODE_NONE
,CHOICE_MODE_SINGLE
orCHOICE_MODE_MULTIPLE
-
getCount
public int getCount()- Specified by:
getCount
in interfaceandroid.widget.Adapter
-
getItem
- Specified by:
getItem
in interfaceandroid.widget.Adapter
-
getItemId
public long getItemId(int filteredPosition) - Specified by:
getItemId
in interfaceandroid.widget.Adapter
-
setItemChecked
public void setItemChecked(int filteredPosition, boolean checked) -
toggleChecked
public void toggleChecked(int filteredPosition) -
setAllItemsChecked
public void setAllItemsChecked(boolean checked) -
setItemChecked
public void setItemChecked(long id, boolean checked) -
setItemsCheckedFromIds
-
setItemsCheckedFromIds
public void setItemsCheckedFromIds(long[] checkedItemIds) -
isItemChecked
public boolean isItemChecked(int filteredPosition) -
getCheckedItemCount
public int getCheckedItemCount() -
getCheckedItems
-
getCheckedItemOriginalPositions
-
getCheckedItemIds
-
filterItems
protected void filterItems() -
highlight
Highlights everything that matched the current filter (if any) in text- Parameters:
text
- the text to highlightcontext
- a context to get the default highlight color from- Returns:
- a spannable string
-
highlight
Highlights everything that matched the current filter (if any) in text- Parameters:
text
- the text to highlightcolor
- the highlight color- Returns:
- a spannable string
-
notifyDataSetChanged
public void notifyDataSetChanged()- Overrides:
notifyDataSetChanged
in classandroid.widget.BaseAdapter
-
getView
public android.view.View getView(int position, android.view.View convertView, android.view.ViewGroup parent) - Specified by:
getView
in interfaceandroid.widget.Adapter
-