> Thanks for the explanation. Most helpful. I now understand that one
> can have any view to render a row by overriding the getView() method.

Or by supplying your own layout XML identifier
(R.layout.somethingoranother), if the rows are reasonably simple. I'm a
bit of a control freak, so I prefer overriding getView(), but that's just
me.

> My original question though still stays. If given a "resource id" for
> a view, how can one create multiple instances of that view?

http://code.google.com/android/reference/android/view/ViewInflate.html

ViewInflate#inflate() will create a new View based on a supplied resource ID.

For example:

ViewInflate inflater=getViewInflate(); // assumes you're in an Activity
View view=inflater.inflate(R.layout.tourview_std, null, null);
TextView distance=(TextView)view.findViewById(R.id.distance);
ImageView turn=(ImageView)view.findViewById(R.id.turn);
ImageView marker=(ImageView)view.findViewById(R.id.marker);
TextView waypoint=(TextView)view.findViewById(R.id.waypoint);

Here, I inflate R.layout.tourview_std, then use findViewById() to get at
the innards. I can then set the text and images as needed.

For better performance, examine the View convertView parameter passed into
your getView() callback. If it's the right View to use (e.g., you're only
inflating one type of row), then just reuse that instance, since it's one
you inflated earlier. If it's null or the wrong view (e.g., you've got
several types of rows, each with different layouts), inflate yourself a
new one. The inflation process isn't the speediest, so the fewer inflates
you can do, the better.

Hope this helps!

-- 
Mark Murphy (a Commons Guy)
http://commonsware.com
_The Busy Coder's Guide to Android Development_ -- Available Now!


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google
Groups "Android Developers" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[EMAIL PROTECTED]
Announcing the new M5 SDK!
http://android-developers.blogspot.com/2008/02/android-sdk-m5-rc14-now-available.html
For more options, visit this group at
http://groups.google.com/group/android-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to