Search code examples
androidviewadapterviewgroup

How to properly get a View from a ListAdapter?


How do I properly use ListAdapter.getView(int position, View convertView, ViewGroup parent) method? I'm having trouble finding out what the ViewGroup expect.

From what I get:

  • position is the element number that i want
  • convertView is the View that I defined for the items in my layout
  • parent = ?

Solution

  • parent is the ListView (or other type of ViewGroup) whose data is being supplied by the ListAdapter.

    Note: You shouldn't really be calling this method directly. It is an Adapter interface method you typically override in your own BaseAdapter subclass to give you complete control over how the views are displayed for each item in the list.