question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

long list show incorrect list items on custom listview with images from android universal image loader

See original GitHub issue

I tried to display a custom list view that display custom list items with image and text lines. I want two type of list items (left align and right alined, just as message thread). I have used Android-Universal-Image-Loader to load web images. bt when i load the list, it load wrong list items time to time. when i scroll fast it changed the alignment of list items time to time.

screenshot_2013-11-26-13-39-31

here u can see the one user (a girl profile picture) reply not in a right aligned all the time

here’s my coding,

    DisplayImageOptions options = new DisplayImageOptions.Builder()
      .showImageForEmptyUri(R.drawable.social_person)
      .showStubImage(R.drawable.ic_launcher)
      .showImageOnFail(R.drawable.ic_launcher)
      .showStubImage(R.drawable.social_person)
      .cacheInMemory(true)
      .cacheOnDisc(true)
      .displayer(new RoundedBitmapDisplayer(20))
      .build();
    @Override
        public View getView(final int position, View convertView, ViewGroup parent) {

        ViewHolder vh = null;       
        threadMessageObj = threadMessagesList.get(position);

        mSenderId = threadMessageObj.getSenderID();

        if(convertView == null){    
            vh = new ViewHolder();

            if(threadMessageObj.getSenderID().equals(mLoggedUserID)){ 
                convertView = inflater.inflate(R.layout.thread_message_row_right, null);
                vh.messageTxt = (TextView) convertView.findViewById(R.id.message_body_r);
                vh.dateTimeView = (TextView) convertView.findViewById(R.id.message_datetime_r);
                vh.imageView = (ImageView) convertView.findViewById(R.id.receipient_image);
            }else{
                convertView = inflater.inflate(R.layout.thread_message_row_left, null);
                vh.messageTxt = (TextView) convertView.findViewById(R.id.message_body);
                vh.dateTimeView = (TextView) convertView.findViewById(R.id.message_datetime);
                vh.imageView = (ImageView) convertView.findViewById(R.id.sender_image);

            }

            convertView.setTag(vh);

        }else{
            vh = (ViewHolder) convertView.getTag();

        }

        String messageText = null;
        String messageTimeText = null;
        String messageDateText;
        String mSenderImage = null;


        mSenderImage = threadMessageObj.getSenderImage();
        imageUri = ConstantValues.API_IP_NEW +  threadMessageObj.getSenderImage(); // from Web

        if( threadMessageObj.getMessageTime() != null){
            messageTimeText = threadMessageObj.getMessageTime().trim();
        }

        if( threadMessageObj.getMessageBody() != null){
            messageText = threadMessageObj.getMessageBody().trim();
        }

        String DateTimeArray[] = messageTimeText.split("\\s+");
        String dateTxt = DateTimeArray[0];
        String timeTxt = DateTimeArray[1];

        String processedTime = vip.getProcessedDate(dateTxt) + " " +  vip.getProcessedTime(timeTxt);

        if(messageText != null){
            vh.messageTxt.setText(messageText);
        }else{
            vh.messageTxt.setText("");
        }
        if(messageTimeText != null){ 
            vh.dateTimeView.setText(processedTime); 
        }

        String[] imageUrls = new String[imageURIList.size()];
        imageUrls = imageURIList.toArray(imageUrls);

        if(mSenderImage != null){
            imageLoader.displayImage(imageUri, vh.imageView, options, animateFirstListener);
        }else{
            imageLoader.displayImage(null, vh.imageView);
        }

        return convertView;

    }// end getView

how to get solved this issue?

Issue Analytics

  • State:closed
  • Created 10 years ago
  • Comments:5 (2 by maintainers)

github_iconTop GitHub Comments

2reactions
guoyongxincommented, Nov 26, 2013

You should check your holder here

else{
        vh = (ViewHolder) convertView.getTag();

    }

If the holder holds the view you want, you can reuse it. If not you should instantiate a new one.

Hope this could help 😃

0reactions
nostra13commented, Nov 26, 2013

Eventually you can ask for help on StackOverFlow - http://stackoverflow.com/

Read more comments on GitHub >

github_iconTop Results From Across the Web

android - Universal Image Loader Showing Wrong Images for ...
I am a beginner in android coding...And I stumbled On this problem where UIL is showing wrong images for wrong items in a...
Read more >
ListView with Images and Text [Scroll With NO Lag] - YouTube
Android Beginner Tutorial #10 - ListView with Images and Text [Scroll With NO Lag]By the end of this video you will know how...
Read more >
Android ListView with Custom Adapter Example Tutorial
In this tutorial we'll build an application that consists of list of rows displaying text descriptions and an info icon. Clicking the row...
Read more >
Customizing ListView Cell Appearance - Xamarin
Forms ListView class is used to present scrollable lists, which can be customized through the use of ViewCell elements.
Read more >
Android ListView Universal Image Loader Changes ... - iTecNote
When I scroll through the list, all the profile pictures load fine and work great. But as I scroll, the status photos do...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found