kingkung wrote:
> I followed your suggestion and created my own version of ArrayAdapter,
> overriding getView().
>
> Everything works, however, with some logging, I'm finding that
> getView() is not called n times (n=number of items in list), but 2n+1
> times (getView() is called 3 times for the first list item, two times
> apiece for the rest). This significantly increases my application
> startup time as I call ViewInflate everytime during getView().
>
> Is this normal (should ArrayAdapter really be calling getView() more
> than n times)? And if so, any suggestions on how to optimize?
The second parameter to getView() is a View. If that view is not null,
that means it's one you created earlier that needs repopulating. Your
choices then are:
1. Just ignore it and return a fresh view.
2. Reuse the supplied view.
For example:
public View getView(int position, View convertView, ViewGroup parent) {
TextView label=(TextView)convertView;
if (convertView==null) {
convertView=new TextView(ctxt);
label=(TextView)convertView;
}
label.setText(items[position]);
return(convertView);
}
In this case, the View is just a TextView, but the same concept holds
for ones you inflate.
Hope this helps!
--
Mark Murphy (a Commons Guy)
http://commonsware.com
The Busy Coder's Guide to Android Development -- coming in June 2008!
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---