2

I am wondering how we can create CardView Lists (dynamically generated cardview items). I'm surprised I can't find any info on how to create CardView lists on the developer.android.com site. I can usually find whatever I'm looking for.

I have seen quite a lot of stuff online but from what I've seen, its still using generic views, not CardViews. How can we create a list with cardviews?

username
  • 289
  • 4
  • 19
  • You want to create a list with many different CardView items in it, or a CardView with a list inside it? – Benjamin Scharbau Dec 11 '15 at 01:09
  • Urm... @Benjamin, a list with many different CardView items in it – username Dec 11 '15 at 01:11
  • Just to add, when I implemented a ListView of clickable CardViews, this answer was helpful for getting the selector states working on all api levels, it's a little tricky since on pre-api 21 the elevation is "fake": http://stackoverflow.com/a/30192562/4409409 – Daniel Nugent Dec 11 '15 at 01:37
  • Thanks Daniel. I'll check that out. :) – username Dec 11 '15 at 04:26

1 Answers1

4

I am wondering how we can create CardView Lists (dynamically generated cardview items)

Use ListView or RecyclerView. Use CardView as the root layout for your row layouts, wrapping around whatever the "real" stuff is in the row. And you're done.

RecyclerView will be the more common choice, simply because it was released at the same time as CardView. Many of my RecyclerView samples use CardView, such as this one and this one.

I'm surprised I can't find any info on how to create CardView lists on the developer.android.com site

That's because there is nothing much different about creating a list containing CardView widgets than there is about creating a list containing any other sort of widget. CardView is just a subclass of FrameLayout with a nice drop shadow effect. It is not rocket science, nor is it brain surgery.

CommonsWare
  • 986,068
  • 189
  • 2,389
  • 2,491
  • Thanks @Commoms. I'm still really new to Android dev. Finding it a bit difficult coming from the .net world – username Dec 11 '15 at 01:14