android – How can I make a list of lists with a RecyclerView and GridLayoutManager-ThrowExceptions

Exception or error:

I have a list of days and every day has a list of events. How do I show the list of events within the day item? same as google calendar

example
https://lh3.googleusercontent.com/bWNeO_FeYhGvuJ2UGNTrYVXWk4G3Re21-sOgdjM5V7ZaxehFUJDq7qaevvASs5tnbLNL=w1536-h674-rw

How to solve:

In you day cell, create another recycler view that hold ( vertical item ). Assume that each position have different list of data so collect data from each parent position and set to childAdapter of each position

Example:

  1. Assume that you have a calendar using recycler view which holding data by ParentViewHolder.
  2. In your ParentViewHolder Create Another Recycler View Like ChildRecyclerView.
  3. Create ChildAdapter for ChildRecyclerView that holding vertical item using ChildViewHolder.
  4. Add your necessary action on ChildViewHolder.

###

1.The day item view in a RecyclerView with a GridLayoutManger

2.The event item view in a RecyclerView with a LinearLayoutManger

3.Set the event RecyclerView’s height to wrap_content

4.To make good performance you should make all RecyclerView use a same RecyclerViewPool:

In Activity/Fragment:

// field
var globalViewPool = RecycledViewPool()
// ....

// init view
dayRecyclerView.setRecycledViewPool(globalViewPool)

In EventAdapter:

// onCreateViewHolder
eventRecyclerView.setRecycledViewPool(globalViewPool)

Leave a Reply

Your email address will not be published. Required fields are marked *