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

Working with Recyclerview

Sponsored · Ship Features Fearlessly Turn features on and off without deploys. Used by thousands of Ruby developers. →

Working with Recyclerview

Mostly mobile apps rely on showing data as a list. This talk will cover basic stuff about working with RecyclerView explaining showing different view types, customizing item decorations, etc.

Avatar for Poe Poe Myint Swe

Poe Poe Myint Swe

November 12, 2016

Other Decks in Programming

Transcript

  1. Components • RecyclerView: create view, bind data and recycles •

    Adapter: provide data • ViewHolder: hold sub views • LayoutManager: layout and position view • ItemDecorator: decorate each item • ItemAnimator: animate changes
  2. • getItemType(): return item type by data type • onCreateView():

    inflate & create different view holder according to item type • onBindView(): bind data according to holder
  3. // Create a model object inside adapter
 public class ListItem

    {
 public Object item;
 public int itemType;
 }
  4. private ArrayList<LitItem> items = new ArrayList<>();
 private void createItems() {


    items.clear();
 
 LitItem listItem = new LitItem();
 listItem.item = "This is example text";
 listItem.itemType = 1;
 
 LitItem listItem2 = new LitItem();
 listItem.item = 100;
 listItem.itemType = 2;
 
 LitItem listItem3 = new LitItem();
 listItem.item = 10f;
 listItem.itemType = 3;
 }
  5. Mistakes • Any UI or View changes user made need

    to tie to data item. • Notify the changes, ALWAYS. • Get the item count right!