开发者

Multiple Views for for a row in a ListView

开发者 https://www.devze.com 2022-12-16 12:33 出处:网络
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

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

精彩评论

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

关注公众号