Images are repeating in ListView

后端 未结 6 1623
遥遥无期
遥遥无期 2020-12-15 12:49

I have implemented android app which should download images from server and display them in ListView, but very interesting thing occures while images are downloading

6条回答
  •  一整个雨季
    2020-12-15 13:01

    I have spent hours trying to figure this one out as well...Thanks to Steven Byle's solution... Here is my solution to something similar when a user selects an item from a list:

    adapter.setSelectedIndex(position);
    

    then in the custom adapter:

    public void setSelectedIndex(int ind)
    {
        selectedIndex = ind;
        notifyDataSetChanged();
    }
    

    and then finally in the getView method of the adapter:

    if(selectedIndex!= -1 && position == selectedIndex)
             {
                 holder.tab.setBackgroundColor(Color.BLACK);
             }
             else{
                 holder.tab.setBackgroundColor(Color.DKGRAY);
             }
    

    So in conclusion make sure you assign default values

提交回复
热议问题