Wrong image show up in my ListView rows

后端 未结 3 1787
孤街浪徒
孤街浪徒 2020-12-10 06:46

I use this code in my getView:

@Override
public View getView(int position, View convertView, ViewGroup parent) {
    View v = convertView;
    if (v == null)         


        
3条回答
  •  無奈伤痛
    2020-12-10 07:26

    I tried using the solution marked here as correct, but it doesn't solve the problem of wrong image during scrolling. I tryied the second one (Zsombor Erdődy-Nagy) and now it's really ok. So thanks Zsombor :-)

    Here it is my snippet:

        @Override
    public View getView(int position, View convertView, ViewGroup parent) {
        /*
        View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.tweet_list, null);
        }
        */
        LayoutInflater vi = (LayoutInflater) getContext().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        View v = vi.inflate(R.layout.tweet_list, null);
        final Status status = getItem(position);
        if (status != null) {
            TextView statusName = (TextView) v.findViewById(R.id.statusName);
            TextView statusText = (TextView) v.findViewById(R.id.statusText);
            TextView statusWhen = (TextView) v.findViewById(R.id.statusWhen);
            TextView statusScreenName = (TextView) v.findViewById(R.id.statusScreenName);
            final ImageView statusUserImage = (ImageView) v.findViewById(R.id.statusUserImage);
            statusName.setText(status.getUser().getName());
            statusScreenName.setText("@" + status.getUser().getScreenName());
            statusText.setText(status.getText());
            statusWhen.setText(dateTimeFormatter.format(status.getCreatedAt()));
            URL url = status.getUser().getProfileImageURL();
            String imageCacheKey = url.getPath();
            Drawable cachedImage = imageCache.get(imageCacheKey);
            if (null != cachedImage) {
                statusUserImage.setImageDrawable(cachedImage);
            } else {
                new DownloadImageTask(statusUserImage, imageCacheKey).execute(url);
            }
    
        }
        return v;
    }
    

提交回复
热议问题