Upgrade to Pro — share decks privately, control downloads, hide ads and more …

RecyclerView

Kevin McMahon
November 19, 2014

 RecyclerView

Quick intro talk about the RecyclerView given to Chicago's AndroidListener group on November 19, 2014

Kevin McMahon

November 19, 2014
Tweet

More Decks by Kevin McMahon

Other Decks in Programming

Transcript

  1. public final static class ListItemViewHolder extends RecyclerView.ViewHolder { TextView label;

    TextView dateTime; public ListItemViewHolder(View itemView) { super(itemView); label = (TextView) itemView.findViewById(R.id.txt_label_item); dateTime = (TextView) itemView.findViewById(R.id.txt_date_time); } }
  2. public class RecyclerView extends ViewGroup { public static abstract class

    LayoutManager { // The required bits to implement public abstract LayoutParams generateDefaultLayoutParams(); public void scrollToPosition(int position) { if (DEBUG) { Log.e(TAG, "You MUST implement scrollToPosition. It will soon become abstract"); } } public void onLayoutChildren(Recycler recycler, State state) { Log.e(TAG, "You must override onLayoutChildren(Recycler recycler, State state) "); } } }
  3. DEFAULT IMPLEMENTATION /** * A {@link android.support.v7.widget.RecyclerView.LayoutManager} implementation which provides

    * similar functionality to {@link android.widget.ListView}. */ public class LinearLayoutManager extends RecyclerView.LayoutManager { /* REALLY INTERESTING CODE HERE */ }
  4. public static abstract class ItemDecoration { /* drawn before the

    item views */ public void onDraw(Canvas c, RecyclerView parent, State state) {} /* drawn after the item views */ public void onDrawOver(Canvas c, RecyclerView parent, State state) {} /* adjusts the item insets to give space if necessary for the decoration */ public void getItemOffsets(Rect outRect, View view, RecyclerView parent, State state) {} } BIG NOTA BENE : These methods are not called of each item individually but just once for the RecyclerView
  5. public static abstract class ItemAnimator { abstract public void runPendingAnimations();

    abstract public boolean animateRemove(ViewHolder holder); abstract public boolean animateAdd(ViewHolder holder); abstract public boolean animateMove(ViewHolder holder, int fromX, int fromY, int toX, int toY); abstract public boolean animateChange(ViewHolder oldHolder, ViewHolder newHolder, int fromLeft, int fromTop, int toLeft, int toTop); abstract public void endAnimation(ViewHolder item); abstract public void endAnimations(); abstract public boolean isRunning(); }
  6. DEFAULT IMPLEMENTATION /** * This implementation of {@link RecyclerView.ItemAnimator} provides

    basic * animations on remove, add, and move events that happen to the items in * a RecyclerView. RecyclerView uses a DefaultItemAnimator by default. */ public class DefaultItemAnimator extends RecyclerView.ItemAnimator { /* REALLY INTERESTING CODE HERE */ }