0

I am aware that you can extend BaseAdapter and override the getViewTypeCount() and getItemViewType(postion) methods and get various row layouts that way.

However, I have just done a tutorial in which ArrayAdapter was extended and getView(int position, View convertView, ViewGroup parent) was the only method overriden.

It seems to me a lot simpler just to follow this approach and use the position maybe with an if/switch to determine the view inflated for a given row.

Is that a correct assumption or are there problems with this approach?

Cheers

mgibson
  • 6,103
  • 4
  • 34
  • 49

1 Answers1

5

no your assumption is wrong. if you need to inflate different Views the correct way is to override getViewTypeCount()/ getItemViewType(postion) pairs. In this way android will give you a different convertView to inflate based on what the getViewTypeCount() returns.

as stand in the docs:

getViewTypeCount() Returns the number of types of Views that will be created

Blackbelt
  • 156,034
  • 29
  • 297
  • 305