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.