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!
  • Field Details

  • Constructor Details

    • AdvancedAdapter

      public AdvancedAdapter()
  • Method Details

    • setData

      public void setData(T[] list)
      Set this adapters data
      Parameters:
      list - a list of objects to be maintained by this adapter
    • setData

      public void setData(ArrayList<? extends T> list)
      Set this adapters data
      Parameters:
      list - an array-list of objects to be maintained by this adapter
    • setData

      public void setData(T[] list, AdvancedAdapter.ItemIdentifier<T> identifier)
      Set this adapters data and ids
      Parameters:
      list - a list of objects to be maintained by this adapter
      identifier - an Identifier returning a unique id for every item
    • setData

      public void setData(ArrayList<? extends T> list, AdvancedAdapter.ItemIdentifier<T> identifier)
      Set this adapters data and ids
      Parameters:
      list - an array-list of objects to be maintained by this adapter
      identifier - an Identifier returning a unique id for every item
    • setDataAndIds

      public void setDataAndIds(T[] list, long[] ids)
    • setDataAndIds

      public void setDataAndIds(ArrayList<androidx.core.util.Pair<T,Long>> list)
    • getData

      public ArrayList<T> getData()
      Get the data maintained by this adapter
      Returns:
      an array-list of the data
    • getFilter

      @Nullable public AdvancedAdapter<T>.AdvancedFilter getFilter()
      Overwrite this method to return your AdvancedFilter here
      Specified by:
      getFilter in interface android.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 to CHOICE_MODE_SINGLE, the list allows up to one item to be checked Using CHOICE_MODE_MULTIPLE, any number of items may be checked.
      Parameters:
      choiceMode - One of CHOICE_MODE_NONE, CHOICE_MODE_SINGLE or CHOICE_MODE_MULTIPLE
    • getCount

      public int getCount()
      Specified by:
      getCount in interface android.widget.Adapter
    • getItem

      public T getItem(int filteredPosition)
      Specified by:
      getItem in interface android.widget.Adapter
    • getItemId

      public long getItemId(int filteredPosition)
      Specified by:
      getItemId in interface android.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

      public void setItemsCheckedFromIds(ArrayList<Long> checkedItemIds)
    • setItemsCheckedFromIds

      public void setItemsCheckedFromIds(long[] checkedItemIds)
    • isItemChecked

      public boolean isItemChecked(int filteredPosition)
    • getCheckedItemCount

      public int getCheckedItemCount()
    • getCheckedItems

      public ArrayList<T> getCheckedItems()
    • getCheckedItemOriginalPositions

      public ArrayList<Integer> getCheckedItemOriginalPositions()
    • getCheckedItemIds

      public ArrayList<Long> getCheckedItemIds()
    • filterItems

      protected void filterItems()
    • highlight

      protected android.text.Spannable highlight(String text, android.content.Context context)
      Highlights everything that matched the current filter (if any) in text
      Parameters:
      text - the text to highlight
      context - a context to get the default highlight color from
      Returns:
      a spannable string
    • highlight

      protected android.text.Spannable highlight(String text, int color)
      Highlights everything that matched the current filter (if any) in text
      Parameters:
      text - the text to highlight
      color - the highlight color
      Returns:
      a spannable string
    • notifyDataSetChanged

      public void notifyDataSetChanged()
      Overrides:
      notifyDataSetChanged in class android.widget.BaseAdapter
    • getView

      public android.view.View getView(int position, android.view.View convertView, android.view.ViewGroup parent)
      Specified by:
      getView in interface android.widget.Adapter