开发者

Multiple Views for for a row in a ListView

I have a ListView that could have 4 different views for a row depending on the data for the row. I have the ListView working correctly overriding getViewTypeCount and getItemViewTYpe. I originally was trying to dynamiclly update the view type count as new views were inflated by forcing calls to getViewTypeCount because it was possible that maybe one or two views may be all that would be needed. The app never functioned correctly crashing after there was more than one view added. The problem was fixed by setting getViewTypeCount to always return 4. I noticed getViewTypeCount is automatically called on app start-up and never called again unless a for开发者_如何学编程ce call is made. So I'm just curious if this can be changed dynamically or do you need to know the number of max views you can possibly have and override getViewTypeCount to return that max value.

Vince


The view types count cannot be changed dynamically. You need to return the max number of views you are going to use. Note that you can always give a number bigger than what you will actually need, it won't really matter. Just make sure the number is never less than what you'll need :)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜