Hi Mark,

Thanks for the detailed explanation. This helps tremendously.

Can you please also clarify what do you mean by "use the same instance  
as the convertView" parameter? Dont I need a new View instance for  
every cell being displayed? i.e., if displaying 5 TextView rows at the  
same time, then do we need need 5 different instances of TextView? OR  
is it the case that the getView() method is called only when the View  
is about to be drawn and therefore a single instance will suffice for  
displaying the whole list ?

Thanks,
Nitin.


On Jul 1, 2008, at 3:19 PM, Mark Murphy wrote:

>
>> 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