ListView is not showing correct values after scrolling

后端 未结 1 1489
时光说笑
时光说笑 2021-02-06 15:59

In my application I am using a CustomListView with an ArrayAdapter to show different countries time. But after 6 to 7 rows(depending on the phone scree

1条回答
  •  离开以前
    2021-02-06 16:32

    ListViews recycle views, which means at first a base set of list entries is inflated from XML. When you scroll down now, one list entry gets hidden at the top, and a new one gets shown at the bottom. At this moment getView() is called with a non-null argument convertView, because an already inflated view is reused.

    In your case that means that the whole layout inflation/setup is skipped (the if (v == null) tree). Which is fine, basically all you have to do is update the timestamp in the second if section (o != null).

    It should contain something similar to this, like you did with the textviews too:

    CustomAnalogClock customAC = (CustomAnalogClock) v.findViewById(R.id.yourclockid);
    customAC.setTime(o.getOrderTime());
    

    This means that you have to assign an ID (by using setId()) to your view while adding it to the layout, and also have to have a setTime() method ready.

    0 讨论(0)
提交回复
热议问题