1

My goal is to populate a recycler view with at least two different types of data. First item of the recycler view is a another recycler view that can scroll horizontally. The rest of the items can scroll vertically. Data is backed by room database as a single source of truth which is backed by network data. I looked at the android official sample and code labs. But failed to understand how can I create a paged list for multiple views and how to display them via a PagedListAdapter. If I am not clear enough, please ask question about that part. image sample: https://i.stack.imgur.com/6wZ7j.png

Phantômaxx
  • 37,901
  • 21
  • 84
  • 115
rCr_BD
  • 11
  • 3

1 Answers1

1

I believe you're complicating the problem. The pager adapter can help you with the main paging, the "horizontal" recyclerview is a completely different RV with its own adapter (that can also be used as a pager I'm sure -have not tried this -).

You have a List of Things that you pass to your main RV's adapter.

Given a Thing that looks like:

data class Things(val type: Int = 0, val name: String);

Your adapter's callback...

override fun onCreateViewHolder(parent: ViewGroup, viewType: Int)...

gets a viewType.

So you likely override

   override fun getItemViewType(position: Int): Int {
       return getItem(position).type
   }

So imagining your onCreateViewHolder now looks like

val inflater = LayoutInflater.from(parent.context)
return when (viewType) {
     0 -> BigViewHolderThatHasAnotherRecyclerViewInsideGoodLuckWithThat()
     1 -> NormalViewHolderForAllTheOtherRows()
}

Or similar...

So... where is your problem in all this? :)

Martin Marconcini
  • 26,875
  • 19
  • 106
  • 144