0

I have implemented a custom adapter class which extends ArrayAdapter. I have tried to make this as efficient as possible by making use of the ViewHolder approach, since from what I could learn, the xml inflation performed in the adapter's getView(...) method is a fairly involved process which should be done as few times as possible.

With this in mind, here is my scenario:

I have a ListView with 6 possible items that can be displayed in the list. All 6 items look fairly alike, their differences are that they have different icons, different text and might have an additional image/icon displayed in the item itself.

Every time the adapter's getView(...) method is called I therefore only change the icons, text and make certain elements visible/invisible based on the item I am dealing with,but I only inflate a single xml file - and this is done only once.

My question is the following:

Is my current approach less efficient than making 6 separate xml item layouts, inflating each of these 6 items only once, and then recycling these views for each item. This would mean the setVisibility(...), setImageResource(...) etc. methods will no longer need to be called each time getView(...) is called, but I am now inflating the xml once for each item type (6 inflations rather than one).

My gut feeling tells me that the efficiency improvement I gained from only inflating one xml layout, is probably countered by all the setImageResource(...) calls I am making in getView(...). Am I right?

I know this is a fairly specific question, but I feel any answers will help me to understand the custom adapters in Android a little bit better and I appreciate any feedback.

dabarnard
  • 83
  • 1
  • 6
  • I think you have inflate single xml and try to show-hide or change value of item as list data which more efficient rather than 6 different xml inflation. – Haresh Chhelana Aug 18 '14 at 11:00
  • Check out this answer. http://stackoverflow.com/a/4777306/898295 – dzsonni Aug 18 '14 at 11:45
  • Thanks for the feedback. This is how I have it implemented at the moment. I will stick with this approach for the time being. I was just wondering whether there is merit to my concern that the other methods called in getView(...) with this approach will start to take a performance toll eventually. 6 one-time layout inflations vs all those setImageResource(...), setVisibility(...) etc. calls done each time getView(..) is called. – dabarnard Aug 18 '14 at 12:30

0 Answers0