1

This is very strange, when i scroll slow or medium everything is okay, but then i scroll really fast, sometimes (1/5) pictures are loaded in wrong position.

View mView;
    ViewHolder holder;

    if (convertView == null) {
        LayoutInflater inflater = (LayoutInflater) mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mView = inflater.inflate(R.layout.item_suggested_user, parent, false);
        holder = new ViewHolder();

        holder.circleImage = (CircleImageView) mView.findViewById(R.id.circle_image);
        holder.fullName = (TextView) mView.findViewById(R.id.item_suggested_fullname);
        holder.img1 = (SmartImageView) mView.findViewById(R.id.item_suggested_img1);


        mView.setTag(holder);

    }else{
        mView = convertView;
        holder = (ViewHolder) mView.getTag();
    }


    final SuggestedUsersModel item = (SuggestedUsersModel) getItem(position);
    holder.fullName.setText(mList.get(position).getFullname());

    if (item.getProfilepictureurl() != null) {
        Picasso.with(mContext)
                .load(item.getProfilepictureurl().replaceAll(" ", "%20"))
                .placeholder(R.drawable.ic_contact)
                .error(android.R.drawable.ic_dialog_alert)
                .into(holder.circleImage);
    } else {
        holder.circleImage.setImageResource(R.drawable.ic_contact);
    }

        String type = item.getPosts().get(0).getMediatype();
        //For Image 1
        if (type.equalsIgnoreCase("text")) {
            holder.img1.setImageResource(R.drawable.text_post_background);
        } else if (type.equalsIgnoreCase("image")) {
            if (item.getPosts().get(0).getUri() != null) {

                Picasso.with(mContext)
                        .load(item.getPosts().get(0).getUri().replaceAll(" ", "%20"))
                        .placeholder(R.drawable.ic_contact)
                        .error(android.R.drawable.ic_dialog_alert)
                        .into(holder.img1);
            } else {
                holder.img1.setImageResource(R.drawable.ic_contact);
            }
        } else {
            if (item.getPosts().get(0).getThumbnailuri() != null) {
                Picasso.with(mContext)
                        .load(item.getPosts().get(0).getThumbnailuri().replaceAll(" ", "%20"))
                        .placeholder(R.drawable.ic_contact)
                        .error(android.R.drawable.ic_dialog_alert)
                        .into(holder.img1);
            } else {
                holder.img1.setImageResource(R.drawable.ic_contact);
            }
        }

I am using Picasso , but i tried almost everything and result is the same. I already know how listview work and all that reuse for item, but this i cannot explain why is happening.

Please give me some ideas and solutions. Thanks

UPDATE 1: I added button, and i change text on click, so here is happening again the same (when scrolling button gets mixed up on other position) , so i is NOT library for loading pictures. Can someone please help.

user1730007
  • 211
  • 1
  • 3
  • 13
  • 1
    Do you really need `View mView;`? – Sergo Pasoevi Mar 13 '14 at 08:52
  • I solved this problem using [this](http://stackoverflow.com/a/3068012/2389078) project and since then suggesting everyone else to do same. This might help you also. – DroidDev Mar 13 '14 at 08:54
  • @fremmedehenvendelser, not really but i tried without also.. – user1730007 Mar 13 '14 at 08:55
  • @VishwasSharma, i am not in position to choose what to use, but i don't thing library is causing the problem coz i already tried few. – user1730007 Mar 13 '14 at 08:59
  • reading [this](http://stackoverflow.com/a/20311040/2389078) answer should help you to understand why your images get shuffled. This is a very long research after which I chose to use the library that I gave you the link for, above. – DroidDev Mar 13 '14 at 09:03
  • @Vishwas Sharma, so i guess you want to tell that library i am using is not taking care of this? – user1730007 Mar 13 '14 at 09:08
  • I have not seen the code of library that you are using, so I can't tell that this is really the reason. But I wanted to tell you, that, this is one of the main issue which cause the scrolling of images in `listview`. You might wanna check your library code or make corrections, if you can to fix this issue, if it is there in your library code. – DroidDev Mar 13 '14 at 09:11
  • @VishwasSharma, can you please look the update. Any idea? :/ – user1730007 Mar 13 '14 at 12:00
  • Update your code in question. Which has new button code. – user370305 Mar 13 '14 at 12:31
  • did you notified adapter after changing text on button? Problem with adapter is we don't know how its `getView` method works exactly. Do some research on `getView` method of `adapter` and you'll get to know why images and text on buttons is changing. – DroidDev Mar 13 '14 at 12:40
  • read [this](http://stackoverflow.com/a/7739006/2389078) answer carefully over and over again to understand why text and images are changing. Phew, took me a while to find it. – DroidDev Mar 13 '14 at 12:47

1 Answers1

2

Don't use if-else condition for convertView.

Just put,

LayoutInflater inflater = (LayoutInflater)   mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
mView = inflater.inflate(R.layout.item_suggested_user, parent, false);
holder = new ViewHolder();

holder.circleImage = (CircleImageView) mView.findViewById(R.id.circle_image);
holder.fullName = (TextView) mView.findViewById(R.id.item_suggested_fullname);
holder.img1 = (SmartImageView) mView.findViewById(R.id.item_suggested_img1);

Let me know what happen..

user370305
  • 108,599
  • 23
  • 164
  • 151