Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

First image inside a listview sometimes displays wrong image #83

Closed
gbero opened this issue Oct 23, 2012 · 11 comments
Closed

First image inside a listview sometimes displays wrong image #83

gbero opened this issue Oct 23, 2012 · 11 comments

Comments

@gbero
Copy link

gbero commented Oct 23, 2012

First of all, many thanks for the development of this really nice library :)

It seems that I'm experiencing the same problem.
I have like a twitter feed inside my app that displays the picture of the sender, which is loaded using AUIL. I don't know why but the first picture is oftenly not the good one but one of another user (displayed under in the list). I'm using loadermanager with an ImageViewBinder. If I just scroll a little bit down then up to re-display the wrongly image, it becames to be the good one !

Here are my params :

Used in the bindView() method :

ImageLoader.getInstance().displayImage(contactURL, (ImageView) view, AppConstants.displayImageOptionsCache);

This is initialized in the Application entry point.

public static final DisplayImageOptions displayImageOptionsCache = new DisplayImageOptions.Builder()
        .showStubImage(R.drawable.nophotoman)
        .cacheOnDisc()
        .cacheInMemory()
        .resetViewBeforeLoading()
        .build();


ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(getApplicationContext())
        .threadPoolSize(3)
        .threadPriority(Thread.NORM_PRIORITY - 2)
        .memoryCacheSize(1500000)
        .discCacheFileNameGenerator(new Md5FileNameGenerator())
        .build();
 ImageLoader.getInstance().init(config);

Thanks in advance for your help.

@nostra13
Copy link
Owner

Can you show getView(...) method of your adapter?

@gbero
Copy link
Author

gbero commented Oct 24, 2012

Field Contact.AVATAR is retrieved from SQLiteDatabase using an inner join.

FIRSTNAME_N_LASTNAME (is just a SQL concat using '||' of Contact.FIRSTNAME and Contact.LASTNAME) are always correctly displayed.
I've displayed in debugging the URL contained in Contact.AVATAR and it is always correct, but sometimes the imageloaded doesn't correspond to that URL. I hope I'm clear :)

    public boolean setViewValue(View view, Cursor cursor, int index) {
        if (index == cursor.getColumnIndex(Tweet._ID)) {
        ...
        } else if (index == cursor.getColumnIndex(Contact.AVATAR)) {
            if (view.getId() == R.id.item_tweetlist_picture) {
                String contactURL = cursor.getString(index);
                if (contactURL != null) {
                    ImageLoader.getInstance().displayImage(contactURL, (ImageView) view,
                         AppConstants.displayImageOptionsCache);
                } else {
                    ((ImageView) view).setImageResource(R.drawable.nophotoman);
                }
            }
            return true;
        } else if (index == cursor.getColumnIndex(FIRSTNAME_N_LASTNAME)) {
            if (view.getId() == R.id.item_tweetlist_tweet_poster_tv) {
                ((TextView) view).setText(cursor.getString(index));
            }
            return true;
        }

        ....
    }

I really think about a problem regarding view reusage, but I can't find why, this is really very strange.

@nostra13
Copy link
Owner

Do you have this problem only for first item in ListView or for different items?

@gbero
Copy link
Author

gbero commented Oct 29, 2012

It *seems *to only occur on the first item...

@nostra13
Copy link
Owner

I don't know what the problem. I can help you only if you provide me whole project sources (and used libraries) so I can test it and try to find a solution. If you accept this way then send it to my email (look into Readme).

@nostra13
Copy link
Owner

nostra13 commented Nov 5, 2012

7 days, no answer.

@nostra13 nostra13 closed this as completed Nov 5, 2012
@gbero
Copy link
Author

gbero commented Nov 12, 2012

Seems OK since #71
Think both issues were related. Sorry for late answer, thank you for fix & followup

@Grom-S
Copy link

Grom-S commented Jan 17, 2013

Have same issue. Also if you scroll VERY quick up and down. Some images appear in the places where should be empty placeholders (where image not set).
Here is the adapter code

public class ProductAdapter extends CursorAdapter {

    private int rowLayout;
    private LayoutInflater inflater;


    public ProductAdapter(Activity context, int rowLayout, Cursor c) {
        super(context, c, false);

        this.rowLayout = rowLayout;
        this.inflater = context.getLayoutInflater();

    }

    @Override
    public void bindView(View view, Context context, Cursor cursor) {

        String name = cursor.getString(cursor.getColumnIndex("name"));
        TextView nameLabel = (TextView) view.findViewById(R.id.tvProductName);
        nameLabel.setText(name);

        BigDecimal price = CurrencyHelper.prepareForUsage(cursor.getInt(cursor.getColumnIndex("price")));
        TextView priceLabel = (TextView) view.findViewById(R.id.tvProductPrice);
        priceLabel.setText(new CurrencyFormat().format(price));

        String path = cursor.getString(cursor.getColumnIndex("imagePath"));
        ImageView image = (ImageView) view.findViewById(R.id.ivProductImage);

        if (path != null) {
            ImageLoader.getInstance().displayImage("file://" + path, image);
        } else {
            image.setImageBitmap(null);
        }

        Integer id = cursor.getInt(cursor.getColumnIndex("_id"));
        view.setTag(id);
    }

    @Override
    public View newView(Context arg0, Cursor arg1, ViewGroup arg2) {
        return inflater.inflate(rowLayout, null);
    }

}

@nostra13
Copy link
Owner

@Grom-S This is because you set null-Bitmap yourself.
imageLoader calls are asynchronous, image.setImageBitmap(null) is synchronous and can be executed before imageLoader ended his work.

So use ImageLoader.getInstance().displayImage(null, image); instead of image.setImageBitmap(null).

@Grom-S
Copy link

Grom-S commented Jan 17, 2013

@nostra13 sorry, haven't thought about that. thanks a lot.

@razi429
Copy link

razi429 commented Jun 15, 2013

Hey!
Am getting the same issue in ver1.8.4
First image in a list doesn't get displayed when the activity having the list is visited 2nd time..
Noted one thing that this issue is happening only when I have some invalid image links for other images in the list.
If all the image links are fine, then everything gets displayed absolutely fine.

Note : This issue gets replicated even in the Demo shared with the package.
Just replaced the first 5 links in the IMAGES array of Constants class as below.

https://lh6.googleusercontent.com/-jZgveEqb6pg/T3R4kXScycI/AAAAAAAAAE0/xQ7CvpfXDzc/s1024/sample_image_01.jpg

http://wrong.site.com/corruptedLink

http://wrong.site.com/corruptedLink

https://lh6.googleusercontent.com/-jZgveEqb6pg/T3R4kXScycI/AAAAAAAAAE0/xQ7CvpfXDzc/s1024/sample_image_04.jpg

http://wrong.site.com/corruptedLink

Please Help. Thanks in advance.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants