uk.co.ribot.easyadapter
Class ItemViewHolder<T>

java.lang.Object
  extended by uk.co.ribot.easyadapter.ViewHolder
      extended by uk.co.ribot.easyadapter.ItemViewHolder<T>

public abstract class ItemViewHolder<T>
extends ViewHolder

Easier alternative to implementing your own android.widget.BaseAdapter. Extend this class as it's explained below and then use EasyAdapter to link it to your android.widget.AdapterView

  1. Annotate the subclass using LayoutId, i.e @LayoutId(R.id.item_layout). It will link the ItemViewHolder to the item's layout.
  2. Annotate the view fields with ViewId, i.e @ViewId(R.id.textView1). It will look for the viewId's in the item's layout and will assign the views to the annotated fields of the subclass.
  3. Implement onSetValues(Object, PositionInfo) and populate the views using the data in the item object
  4. Optionally, implement onSetListeners(Object, PositionInfo) to add listeners to the views.


Constructor Summary
ItemViewHolder(View view)
          Constructs an item view holder with the item view
ItemViewHolder(View view, T item)
          Constructs an item view holder with the item view and the item data
 
Method Summary
 T getItem()
          Gets the item data
 void onSetListeners(T item, PositionInfo positionInfo)
          Implement this method to add listeners to the views
abstract  void onSetValues(T item, PositionInfo positionInfo)
          Must implement this method to populate the views with the data in the item object.
 void setItem(T item)
          Sets the item data
 
Methods inherited from class uk.co.ribot.easyadapter.ViewHolder
getView
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ItemViewHolder

public ItemViewHolder(View view)
Constructs an item view holder with the item view

Parameters:
view - the parent view where the held views reside.

ItemViewHolder

public ItemViewHolder(View view,
                      T item)
Constructs an item view holder with the item view and the item data

Parameters:
view - the parent view where the held views reside.
item - the data item that is used to populate the held views.
Method Detail

getItem

public T getItem()
Gets the item data

Returns:
the data item that is used to populate the held views.

setItem

public void setItem(T item)
Sets the item data

Parameters:
item - the data item that is used to populate the held views.

onSetValues

public abstract void onSetValues(T item,
                                 PositionInfo positionInfo)
Must implement this method to populate the views with the data in the item object.

Parameters:
item - the data item that is used to populate the held views.
positionInfo - information about the position of the item on the list.

onSetListeners

public void onSetListeners(T item,
                           PositionInfo positionInfo)
Implement this method to add listeners to the views

Parameters:
item - the data item that is used to populate the held views.
positionInfo - information about the position of the item on the list.