Hi, Keith! At the start of the description for the ArrayAdapter class is the following sentence:
To use something other than TextViews for the array display, for instance, ImageViews, or to have some of data besides toString() results fill the views, override getView(int, View, ViewGroup)<http://developer.android.com/reference/android/widget/ArrayAdapter.html#getView(int, android.view.View, android.view.ViewGroup)> to return the type of view you want. The default implementation of this method is what uses the resourceID's to construct the appropriate views for the individual data items. If you're doing it all in code (rather than via XML), then this is where your code to create these views will need to go. The only places this information is used are in this class's implementation of getView(int, View, ViewGroup), and getDropDownView(int, View, ViewGroup). (And they both call the same internal private method to do the work). So, if you will be using a similar technique to create your item views in these two cases, you can put your code to create the per-item views in your own private method, and make getView(...) and getDropDownView(...) call that private method. If these two cases are significantly different, just implement both methods. Either way, the resulting class will not be using the resource IDs, so you can just supply 0 to the ArrayAdapter constructor in your derived class's constructor. On Tuesday, May 3, 2011 2:45:36 AM UTC-7, Keith Bennett wrote: > > Hi, all. I'm a longtime developer but new to Android. I want to > learn how to instantiate visual components in code rather than XML, so > that I better understand the API, and can build UI's dynamically. > > I want to do this with a ListView. I understand that the ListView's > underlying data is provided by an implementation of ListAdapter. > However, when I research the implementations of ListAdapter, I don't > see anything that seems to be helpful. ArrayAdapter seems to be the > closest to what I want, but all its constructors require a > textViewResourceId, defined as "the resource ID for a layout file > containing a TextView to use when instantiating views". But I'm > building everything in code, even the top level View passed to > setContentView(). > > I was under the impression that anything created with xml > configuration files could also be created using the API. How can I do > this? > > Also, do I need to define id's for the objects provided by the > adapter, or is this not necessary because I can refer to them as Java > objects in my code? > > Thanks for any help. > > - Keith > -- 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+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/android-developers?hl=en