How to increment a value on view holder variables in android?

前端 未结 3 1736
深忆病人
深忆病人 2021-01-22 18:18

I have a viewholder in my Android app and I tried to set an incremented value on a textfield. I tried it like following,

Activity



        
3条回答
  •  被撕碎了的回忆
    2021-01-22 18:55

     > But this is incrementing randomly
    

    that is because the viewholder may belong to different order-lines.

    Example

    • in the beginning viewholder#1 belongs to orderline #1 with inc=2
    • if you scroll down the listbox orderline #1 becomes invisible and orderline #27 becomes visible. .
    • now orderline #27 is reusing viewholder#1 and with inc=2

    how to fix this:

    you need an objectmodell that store the data inc, articleid, quantity, unitprice, articlename, ......

     final OrderItem orderItem = (OrderItem) objects.get(position);
     ...
     orderItem.inc++;
    

    See also https://stackoverflow.com/search?q=listview+random

提交回复
热议问题