org.solovyev.android.list
Class ListAdapter<T>

java.lang.Object
  extended by android.widget.BaseAdapter
      extended by org.solovyev.android.list.ListAdapter<T>
All Implemented Interfaces:
android.widget.Adapter, android.widget.Filterable, android.widget.ListAdapter, android.widget.SpinnerAdapter
Direct Known Subclasses:
ListItemAdapter

public class ListAdapter<T>
extends android.widget.BaseAdapter
implements android.widget.Filterable

User: serso Date: 6/6/12 Time: 12:53 AM


Nested Class Summary
 class ListAdapter.AdapterHelper
           
 
Field Summary
 
Fields inherited from interface android.widget.Adapter
IGNORE_ITEM_VIEW_TYPE, NO_SELECTION
 
Constructor Summary
ListAdapter(android.content.Context context, int textViewResourceId)
          Constructor
ListAdapter(android.content.Context context, int resource, int textViewResourceId)
          Constructor
ListAdapter(android.content.Context context, int resource, int textViewResourceId, List<T> elements)
          Constructor
ListAdapter(android.content.Context context, int resource, int textViewResourceId, T[] elements)
          Constructor
ListAdapter(android.content.Context context, int textViewResourceId, List<T> elements)
          Constructor
ListAdapter(android.content.Context context, int textViewResourceId, T[] elements)
          Constructor
 
Method Summary
 void add(T object)
          Adds the specified object at the end of the array.
 void addAll(Collection<? extends T> collection)
          Adds the specified Collection at the end of the array.
 void addAll(T... items)
          Adds the specified items at the end of the array.
 void clear()
          Remove all elements from the list.
 boolean containsInAll(T element)
           
 boolean containsInShown(T element)
           
protected  android.widget.Filter createFilter()
           
static ListAdapter<CharSequence> createFromResource(android.content.Context context, int textArrayResId, int textViewResId)
          Creates a new ListAdapter from external resources.
 void doWork(Runnable runnable)
           
 void filter(String filterText)
           
 void filter(String filterText, android.widget.Filter.FilterListener listener)
           
protected  ListAdapter.AdapterHelper getAdapterHelper()
           
protected  List<T> getAllElements()
           
protected  Comparator<? super T> getComparator()
           
 android.content.Context getContext()
          Returns the context associated with this array adapter.
 int getCount()
          
 android.view.View getDropDownView(int position, android.view.View convertView, android.view.ViewGroup parent)
          
 android.widget.Filter getFilter()
          
 CharSequence getFilterText()
           
 T getItem(int position)
          
 long getItemId(int position)
          
 int getPosition(T item)
          Returns the position of the specified item in the array.
protected  List<T> getShownElements()
           
 android.view.View getView(int position, android.view.View convertView, android.view.ViewGroup parent)
          
 void insert(T object, int index)
          Inserts the specified object at the specified index in the array.
 boolean isNotifyOnChange()
           
 void notifyDataSetChanged()
          
protected  void onDataSetChanged()
           
protected  void onDataSetChanged(boolean resortAndRefilter)
           
 void refilter()
           
 void remove(T object)
          Removes the specified object from the array.
 void removeAt(int position)
           
 void restoreState(android.os.Bundle savedInstanceState)
           
 void saveState(android.os.Bundle outState)
           
 void setDropDownViewResource(int resource)
          Sets the layout resource to create the drop down views.
 void setNotifyOnChange(boolean notifyOnChange)
          Control whether methods that change the list (add(T), insert(T, int), remove(T), clear()) automatically call notifyDataSetChanged().
 void sort(Comparator<? super T> comparator)
          Sorts the content of this adapter using the specified comparator.
 
Methods inherited from class android.widget.BaseAdapter
areAllItemsEnabled, getItemViewType, getViewTypeCount, hasStableIds, isEmpty, isEnabled, notifyDataSetInvalidated, registerDataSetObserver, unregisterDataSetObserver
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ListAdapter

public ListAdapter(@Nonnull
                   android.content.Context context,
                   int textViewResourceId)
Constructor

Parameters:
context - The current context.
textViewResourceId - The resource ID for a layout file containing a TextView to use when instantiating views.

ListAdapter

public ListAdapter(android.content.Context context,
                   int resource,
                   int textViewResourceId)
Constructor

Parameters:
context - The current context.
resource - The resource ID for a layout file containing a layout to use when instantiating views.
textViewResourceId - The id of the TextView within the layout resource to be populated

ListAdapter

public ListAdapter(@Nonnull
                   android.content.Context context,
                   int textViewResourceId,
                   @Nonnull
                   T[] elements)
Constructor

Parameters:
context - The current context.
textViewResourceId - The resource ID for a layout file containing a TextView to use when instantiating views.
elements - The objects to represent in the ListView.

ListAdapter

public ListAdapter(@Nonnull
                   android.content.Context context,
                   int resource,
                   int textViewResourceId,
                   @Nonnull
                   T[] elements)
Constructor

Parameters:
context - The current context.
resource - The resource ID for a layout file containing a layout to use when instantiating views.
textViewResourceId - The id of the TextView within the layout resource to be populated
elements - The objects to represent in the ListView.

ListAdapter

public ListAdapter(@Nonnull
                   android.content.Context context,
                   int textViewResourceId,
                   @Nonnull
                   List<T> elements)
Constructor

Parameters:
context - The current context.
textViewResourceId - The resource ID for a layout file containing a TextView to use when instantiating views.
elements - The objects to represent in the ListView.

ListAdapter

public ListAdapter(@Nonnull
                   android.content.Context context,
                   int resource,
                   int textViewResourceId,
                   @Nonnull
                   List<T> elements)
Constructor

Parameters:
context - The current context.
resource - The resource ID for a layout file containing a layout to use when instantiating views.
textViewResourceId - The id of the TextView within the layout resource to be populated
elements - The objects to represent in the ListView.
Method Detail

add

public void add(T object)
Adds the specified object at the end of the array.

Parameters:
object - The object to add at the end of the array.

onDataSetChanged

protected final void onDataSetChanged(boolean resortAndRefilter)

onDataSetChanged

protected final void onDataSetChanged()

addAll

public void addAll(Collection<? extends T> collection)
Adds the specified Collection at the end of the array.

Parameters:
collection - The Collection to add at the end of the array.

addAll

public void addAll(T... items)
Adds the specified items at the end of the array.

Parameters:
items - The items to add at the end of the array.

insert

public void insert(T object,
                   int index)
Inserts the specified object at the specified index in the array.

Parameters:
object - The object to insert into the array.
index - The index at which the object must be inserted.

remove

public void remove(T object)
Removes the specified object from the array.

Parameters:
object - The object to remove.

removeAt

public void removeAt(int position)

clear

public void clear()
Remove all elements from the list.


sort

public void sort(Comparator<? super T> comparator)
Sorts the content of this adapter using the specified comparator.

Parameters:
comparator - The comparator used to sort the objects contained in this adapter.

notifyDataSetChanged

public void notifyDataSetChanged()

Overrides:
notifyDataSetChanged in class android.widget.BaseAdapter

setNotifyOnChange

public void setNotifyOnChange(boolean notifyOnChange)
Control whether methods that change the list (add(T), insert(T, int), remove(T), clear()) automatically call notifyDataSetChanged(). If set to false, caller must manually call notifyDataSetChanged() to have the changes reflected in the attached view.

The default is true, and calling notifyDataSetChanged() resets the flag to true.

Parameters:
notifyOnChange - if true, modifications to the list will automatically call notifyDataSetChanged()

getContext

@Nonnull
public android.content.Context getContext()
Returns the context associated with this array adapter. The context is used to create views from the resource passed to the constructor.

Returns:
The Context associated with this adapter.

getCount

public int getCount()

Specified by:
getCount in interface android.widget.Adapter

getItem

public T getItem(int position)

Specified by:
getItem in interface android.widget.Adapter

getPosition

public int getPosition(T item)
Returns the position of the specified item in the array.

Parameters:
item - The item to retrieve the position of.
Returns:
The position of the specified item.

containsInShown

public boolean containsInShown(@Nonnull
                               T element)

containsInAll

public boolean containsInAll(@Nonnull
                             T element)

getItemId

public long getItemId(int position)

Specified by:
getItemId in interface android.widget.Adapter

getView

public android.view.View getView(int position,
                                 android.view.View convertView,
                                 android.view.ViewGroup parent)

Specified by:
getView in interface android.widget.Adapter

doWork

public void doWork(@Nonnull
                   Runnable runnable)

setDropDownViewResource

public void setDropDownViewResource(int resource)

Sets the layout resource to create the drop down views.

Parameters:
resource - the layout resource defining the drop down views
See Also:
getDropDownView(int, android.view.View, android.view.ViewGroup)

getDropDownView

public android.view.View getDropDownView(int position,
                                         android.view.View convertView,
                                         android.view.ViewGroup parent)

Specified by:
getDropDownView in interface android.widget.SpinnerAdapter
Overrides:
getDropDownView in class android.widget.BaseAdapter

createFromResource

public static ListAdapter<CharSequence> createFromResource(android.content.Context context,
                                                           int textArrayResId,
                                                           int textViewResId)
Creates a new ListAdapter from external resources. The content of the array is obtained through Resources.getTextArray(int).

Parameters:
context - The application's environment.
textArrayResId - The identifier of the array to use as the data source.
textViewResId - The identifier of the layout used to create views.
Returns:
An ListAdapter.

getFilter

public final android.widget.Filter getFilter()

Specified by:
getFilter in interface android.widget.Filterable

createFilter

@Nonnull
protected android.widget.Filter createFilter()

getShownElements

@Nonnull
protected List<T> getShownElements()

getAllElements

@Nonnull
protected List<T> getAllElements()

getComparator

@Nullable
protected Comparator<? super T> getComparator()

saveState

public void saveState(@Nonnull
                      android.os.Bundle outState)

restoreState

public void restoreState(@Nonnull
                         android.os.Bundle savedInstanceState)

getAdapterHelper

@Nonnull
protected ListAdapter.AdapterHelper getAdapterHelper()

isNotifyOnChange

public boolean isNotifyOnChange()

filter

public void filter(@Nullable
                   String filterText)

filter

public void filter(@Nullable
                   String filterText,
                   @Nullable
                   android.widget.Filter.FilterListener listener)

refilter

public void refilter()

getFilterText

@Nullable
public CharSequence getFilterText()


Copyright © 2014 se.solovyev. All Rights Reserved.