Sunday, September 18, 2011

Re: [android-developers] Listview: heterogenous rows: if statements in XML layout file?

On Sun, Sep 18, 2011 at 3:45 PM, John Goche <johngoche99@googlemail.com> wrote:
> I see now what these BaseAdapter methods are meant to do. You can
> define a certain number of row types each defined by a type integer.
> These default to a type count of 1 with a view type of 0. But I do not
> understand where the view type gets passed in since getView only
> receives a row position. Eventually the data will specify which row
> type to use, so the row position should be enough to identify the
> row type should it not?

Hopefully not. Based on your later comments, you have two row types,
not infinite row types.

> So here we have getView from class Adapter. The position which is
> the row number should be enough to inflate the desired row layout...
> so in this case the two bulleted methods above are not needed?

Not if you have different types of rows. Do not confuse the *type* of
the row (gross layout) with the *contents* of the row (gross layout
with widgets populated with model data).

>> or recycle the supplied convertView -- by overriding the two
>> methods in the previous bullets, you ensure that convertView will be
>> of the desired layout
>
> What do you mean by recycle here?

Please read:

http://commonsware.com/Android/excerpt.pdf

It's a free excerpt from one of my books. You really need to learn
what row recycling is if you are going to extend BaseAdapter. Bear in
mind that you only extend BaseAdapter if your data is not in a data
structure already handled by a more concrete adapter class (e.g.,
ArrayAdapter, CursorAdapter).

--
Mark Murphy (a Commons Guy)
http://commonsware.com | http://github.com/commonsguy
http://commonsware.com/blog | http://twitter.com/commonsguy

Warescription: Three Android Books, Plus Updates, One Low Price!

--
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to android-developers@googlegroups.com
To unsubscribe from this group, send email to
android-developers+unsubscribe@googlegroups.com
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en

No comments:

Post a Comment