Khalil Jomaa Khalil Jomaa - 4 months ago 35
Android Question

Design a RecyclerView with different layouts

I have a

with different

My question is that if I want to add dynamic list on each
, then should I add
on each card or add
on each card?

An example will be appreciated.


To be honest it is not very common to add a RecyclerView inside another. It would be better for you to use a single RecyclerView and populate your list items dynamically. Here a github project to describe how this can be done I'd say have a look. There might be different approaches, this however, is a much faster and efficient way of showing multiple lists in a RecyclerView.

The idea is to add logic in your onCreateViewHolder and onBindViewHolder method so that you can inflate proper view for the exact positions in your RecyclerView.

There is a sample project along with that wiki too. You might clone and check what it does.

There is another way of keeping your items in a single ArrayList of objects so that you can set an attribute tagging the items to indicate which item is from first list and which one belongs to second list. Then pass that ArrayList into your RecyclerView and then implement the logic inside adapter to populate them dynamically. How to add a recyclerView inside another recyclerView

Tell me if this solved your problem ;)