Skip to content

Multiple Cell Types in a List

Question

Can a list contain different types of cell? How to implement it?

Short interview answer

Yes. Model each row’s kind explicitly, choose the corresponding item view or template from that kind, and bind it to the matching data. Keep view selection separate from the list’s underlying data.

Detailed answer

A feed may contain an article row, an advertisement row, and a loading row. Give each item a declared row kind, then have the adapter or template selector create and bind the appropriate view holder or view template. In Android’s RecyclerView model, the adapter owns the mapping between item data and view holders, while the layout manager arranges them. Avoid inferring the cell type from presentation text; an explicit data model makes updates, tests, and accessibility behavior easier to maintain.

Sources