ListView with dyamically selected per row layout
Seen a lot of tutorials with all different types of layout, but not clear on how a layout could be dynamically applied based on the item.
Lets assume a list with items that derive from a common type like book, but a different subclass of book like paperback or audio book would get a completely different layout. So we would have one layout per class/type of object in the list. Evey item has some common properties but others have some additional properties.
So for example
Row 1 Description Text Clickable Button ItemType = A Row 2 Description Text CheckBox ItemType = C Row 3 Description Text Spinner ItemType = B Row 4 Description Text Clickable Button ItemType = A Row 5 Description Text Checkbox ItemType = C
So essentially the item type is determining the layout. ItemType A always have Clickable Item, ItemType C always CheckBox, ItemType B always a Spinner, and all layouts have a description text. I have not seen how the layout would be dynamically applied to list elements based on an element of the array of data. How could this be done or better yet 开发者_如何学Gois there a good example on this. Thanks
Seen a few of these questions lately. One solution is to override the getView
method of the adapter and determine which layout to apply at runtime for each item in your list. It's a fair amount of work, but it does what you want for the non-standard implementation that your asking for.
精彩评论