views:

43

answers:

2

I have a ListView that displays a set of notes, each with varying ammounts of data (i.e. some have a due date, others don't).

Currently, each view in the list is a RelativeLayout containing a TextView for each field, plus two Button and a CheckBox. I then simply hide the unused fields by setting visible false on each one.

This has worked well, but I'm about to add a lot more data fields to the notes and inflating that many unneeded views for each row will surely kill my app. I need a more dynamic solution.

I've decided the best way to go is to create a custom view. How can I implement/design my view so that it can display a variable number of text fields without creating/destroying textviews each time (which would be quite expensive and worse than my current situation), or maintaining a large pool of hidden textviews?

A: 

You can create a class that extends LinearLayout and use addView to dynamically place your views.

Macarse
This would require creating a new textview each time I need to populate my list and destroying old ones. I also would need a way to keep track of them. This is the issue I was trying to avoid in my OP.
CodeFusionMobile
extending `LinearLayout` will allow to use some recycling if you want. If you need to add a TextView first you check if there is any available, if not, create a new one.
Macarse
A: 

Sounds like you might want to look into a view with a stub. The stubs will save space until they are inflated, so each row will be lighter until it is used on a heftier view. If you have a relatively low number of these larger views you might save a bit of overhead.

jqpubliq
That would be nice, but I'm not sure how well that would jive with ListView's recycler. Once the Stub is replaced I'm stuck with replacing a whole mess of views again and I get a one time optomization.
CodeFusionMobile
Ya, once the views have been added I don't see a way around adding/removing or hiding/showing them on recycle. The best scenario I can see is getting some optimization out of views which only end up being recycled for the smaller views.
jqpubliq