开发者

Android ListView is not behaving properly

I am working on a custom ListView for purchasing items in a st开发者_开发问答ore front. You can scroll the list and read product descriptions as well as see product images. For items the user already owns I've pragmatically changed the color of the title (of the product on the list) to a different color so the user can easily identify, "I already own that".

The error I am seeing appears when I scroll to the bottom of the list, and then back to the top. After the UI has been built the titles all color properly, after a complete scroll and return to the top however, the currently owned products are still red and the item under it on the list turns to the "owned" status as well. This will continue happening each time you scroll down the list and back up until the whole list turns into the owned state.

I am not editing my List of products, and this happens on all adapters in my project. Each is unique in the way it populates the product list.

Is there some way I can persist a list of items and tell the View that once its built no more UI changes need be scheduled?

Thanks,

Robert


When you build the list items in the Adapter, you'll need an else-case for everything. I suspect you have something like this:

if (item_is_owned)
   change_color_to_red();

you need an else case:

if (item_is_owned)
   change_color_to_red();
else
   change_color_to_normal();


You could consider using different view types for the Views the adapter creates. One for items that are owned, and the other for items that are not. The Adapter methods getViewTypeCount() and getItemViewType() are used to do this. You'd avoid having to do the if-then-else logic for customizing the View in getView(). Let me know if this answer needs more explanation.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜