Santanu
Santanu

Reputation: 139

ListView scrolling for image in android

In my application images are loaded from server. I have used images loader for image loading. But problem is that , while images are loading, if I scroll the listview , images are shuffled, order of the images are wrong. But after the loading is complete, all images are in correct position. If I scroll now images are not shuffled, they are in correct position. I have used setTag() and getTag() in the listview getView(). Please help me to fix the issue of image shuffling while loading the images in a listview. Here is my code of getView()

public View getView(int position, View convertView, ViewGroup parent) {
        // TODO Auto-generated method stub
        View rowView = convertView;
        ProgressBar progress;
        ImageView image;
        ViewHolder view_holder = null;
        String m_AllImages=m_BaseImageAll.get(position);

        try {

            if (rowView == null) {
                rowView = inflater.inflate(R.layout.photo_show_sub,
                        null);

                view_holder = new ViewHolder();
                view_holder.progress = (ProgressBar) rowView.findViewById(R.id.photoGalProgress);
                view_holder.image = (ImageView) rowView.findViewById(R.id.image);

            }
            else
            {   

                view_holder = (ViewHolder) rowView.getTag();

            }
            imageLoader.displayImage(m_AllImages,
                    activity, view_holder.image, view_holder.progress);

        } catch (Exception ex) {
            ex.printStackTrace();
        }

        return rowView;
    }

Upvotes: 0

Views: 1396

Answers (2)

VIGNESH
VIGNESH

Reputation: 2033

Actually it is not such as the image is getting shuffled , some images gets downloaded faster than the previous , ImageView without image gets wrapped out and the one which is loaded show the image first . so it seems to be shuffled initially unless all the images gets downloaded and its not actually shuffled .

Check it with the dummy image , say

image.setImageBitmap(R.Drawable.ic_launcher);

Upvotes: 2

AndroidLearner
AndroidLearner

Reputation: 4636

Add this line in your code ::

  holder.image.setTag(m_AllImages.get(position));
 imageLoader.displayImage(m_AllImages, activity, view_holder.image, view_holder.progress);

Upvotes: 3

Related Questions