0

Regarding the lisview recycle, I'm reusing the views with viewholder, but now I need to add a number of Views(ImageViews and textviews) not clearcut( the number of views isnt always the same).

How can I add these items, without create a new view on every getView() method and without affecting the performance of the list?

Frederico Silva
  • 338
  • 2
  • 10

2 Answers2

0

No way to create different layouts without overriding getView(). You can reuse as much view types as you want, read this answer.

If you have perfomance issue, try a new widjet RecyclerView, available at Support-V7 library.

Community
  • 1
  • 1
dimetil
  • 3,851
  • 2
  • 29
  • 47
0

my strategy to implement what you described without creating new view every time getView() is called, is:

let's say you have at the most 10 image views. your view xml will contain 10 ImageView items, but when getView() been called - you'll set the visibility of the un-needed elements to View.GONE, and the only ones you needed to View.Visible.

working great for me, and that's the only why not to create new view...

Tal Kanel
  • 10,475
  • 10
  • 60
  • 98
  • So many views in xml and viewholder will not decrease the scroll performance? – Frederico Silva Jul 01 '14 at 15:07
  • from my experience, as long as you play with this amount of views visibility (and not much more) , the UI thread (and scroll speed) will not be affected. besides that - you really not have better solution. as @dimetil said - using RecyclerView can be better to use this case (with my approch), because it have property - mRecyclerView.setHasFixedSize(false) , which adressed exactly this issue of changing dynmically a lot the view params.. – Tal Kanel Jul 01 '14 at 15:13