RecyclerView: Begin with the End in Mind

It is very common for one to use a RecyclerView to show a list of items these days. For a simple project, when I’m about to design one, it’s pretty common I do the below…

  1. Create RecyclerView in the needed Layout XML, and instantiate it in needed class… okay, easy.
  2. Add a Layout Manager to the RecyclerView… simple, since I just need LinearLayoutManager.
  3. Create an Adapter for the RecyclerView… Ops, I can’t complete it, I need a View Holder.
  4. Create the ViewHolder Class and the XML for it… Ops, I don’t have data to populate it yet..
  5. Need to get to design the Data Model, create a list, and fetching the data … Wow… so much thing not done. Need to fetch from Server, Read from File etc.

After doing the step 5… finally now I have the data, get back to Step 4 and 3 to complete everything in a reverse order.

Making a RecyclerView seems to be so much pain. This is because we have so much “incomplete item” to hold on (i.e. step 3 and 4), while we need to work on the next item that the previous item need… and it goes deeper and deeper. My brain stack is limited… stackoverflow!!

The reverse order

Why not let’s try to begin from step 5 instead and going backward…

  1. Design the Data Model, create a list of it… and fetch the data…. Nothing blocking it, could be done
  2. Create the ViewHolder Class and…

--

--