Custom ListView adapter, strange ImageView behavior

后端 未结 2 610
太阳男子
太阳男子 2020-12-04 00:15

I have a custom ListView Adapter, with which I\'m creating rows for a list. My problem is though, that it doesn\'t seem to be distinguishing the

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-12-04 00:30

    you need to define the default image right after finding its reference:

    // find the image
    ImageView favImage = (ImageView)v.findViewById( R.id.toggle_favorite );
    //setting to default
    favImage.setImageResource(R.drawable.default_image);
    // when clicked...
    favImage.setOnClickListener....
    

    you need to do this because once the image is changed, and you scroll the ListView , it reappears because ListView recycles the item views. So you need to define it in getView to use a default image when the list is scrolled

提交回复
热议问题