Am i doing it correctly
No.
there is any other way?
Step #1: Override getViewTypeCount()
in your ListAdapter
and return how many different types of rows you have (e.g., 2). Let's call this value N
.
Step #2: Override getItemViewType()
in your ListAdapter
and return a number, from 0 to N-1
, indicating the particular type of row to use for this position
.
Step #3: In your getView()
method, just return the right row layout for the given position. The convertView
will either be null
(so you create a new one) or it will be a row of the right type (so you just use it).
See also:
- Why do recipes promote overriding getItemViewType and getViewTypeCount when it doesn't seem necessary?
- getViewTypeCount and getItemViewType methods of ArrayAdapter
- https://github.com/thecodepath/android_guides/wiki/Implementing-a-Heterogenous-ListView
- http://antew.com/?p=162
and countless other sources.