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

images display wrong #109

Closed
bhavesh-hirpara opened this issue Nov 23, 2012 · 25 comments
Closed

images display wrong #109

bhavesh-hirpara opened this issue Nov 23, 2012 · 25 comments
Labels

Comments

@bhavesh-hirpara
Copy link

I am loading 5 images..when 1st images get loaded it will be displayed in 1st imageview and randomly in ant one of others imageviews. after loading all images it gradually loads other images and get placed.

    public class PhotoGridAdapter extends BaseAdapter {

    private Context mContext;
    private LayoutInflater infalter;
    private ArrayList<WallPhoto> data = new ArrayList<WallPhoto>();
    ImageLoader imageLoader;

    public PhotoGridAdapter(Context c) {
        infalter = (LayoutInflater) c.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
        mContext = c;

        DisplayImageOptions defaultOptions = new DisplayImageOptions.Builder()
                .cacheInMemory()
                .cacheOnDisc()
                .build();
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(mContext)
                .memoryCache(new WeakMemoryCache())
                .defaultDisplayImageOptions(defaultOptions)
                .build();
        imageLoader = ImageLoader.getInstance();
        imageLoader.init(config);
    }

    @Override
    public int getCount() {
        return data.size();
    }

    @Override
    public WallPhoto getItem(int position) {

        return data.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }

    public void addAll(ArrayList<WallPhoto> files) {

        try {
            this.data.clear();
            this.data.addAll(files);

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

        notifyDataSetChanged();
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        ViewHolder holder;
        if (convertView == null) {
            convertView = infalter.inflate(R.layout.photo_item, null);
            holder = new ViewHolder();

            holder.imgPhoto = (ImageView) convertView.findViewById(R.id.imgMenuIcon);

            convertView.setTag(holder);

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

        try {
            imageLoader.displayImage(data.get(position).url, holder.imgPhoto);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return convertView;
    }

    public class ViewHolder {
        ImageView imgPhoto;
    }
    }
@nostra13
Copy link
Owner

try {
    imageLoader.displayImage(data.get(position).url, holder.imgPhoto);
} catch (Exception e) {
    e.printStackTrace();
}

Why do you try handle some errors here?

Your 5 images are shown together on the screen on activity start? Or you should scroll to see 5th image?

@djj0809
Copy link

djj0809 commented Nov 26, 2012

I guess I have the same problem, images are replaced when imageviews are visible.

@nostra13
Copy link
Owner

@djj0809 Show your display options and configuration and code.

@bhavesh-hirpara
Copy link
Author

@nostra13 Exception handling does not matter at all. If I'll remove exception handling then also it happens. if I am having list view and your loader start loading images, at that time if I scroll my list view and then loaded image @ uppar item may have another place also. but after loading all images each images get placed properly.

@djj0809
Copy link

djj0809 commented Nov 26, 2012

@nostra13 just the default configuration and simple listview with an imageview in each list item...But when I use the imageLoader in Fedor Vlasov's project, it works correctly. I guess the problem may relates to the reuse of the imageView in the adapter.

@nostra13
Copy link
Owner

I think both of you have problem connected to view reusing. And I think the problem solution for you is to call one option: DisplayImageOptions.resetViewBeforeLoading(). Or showStubImage() if you use one.

@bhavesh-hirpara
Copy link
Author

I think so. .. and thanks :)

@bhavesh-hirpara
Copy link
Author

How to load all images by loader and it should be thumb. Have you set DisplayImageOptions for making thumb of downloaded image. If you have implemented like, I have to set only width and height of thumb.

@nostra13
Copy link
Owner

@luminousman Can''t understand you correctly.

@bhavesh-hirpara
Copy link
Author

I mean to say.. imageLoader.displayImage(data.get(position).url, holder.imgPhoto); method will download the image and will set to holder.imgPhoto. @ this url, i don't know the size of photo. but i want to make it thumb image from the downloaded image.

Have any features like :
imageLoader.displayImage(data.get(position).url, holder.imgPhoto,100,100);
where 100 is width and 100 is height for thumb.

this method will download the image and convert it into 100x100 thumb and will set to imageview.

@nostra13
Copy link
Owner

Size of decoded bitmap is defined using android:layout_width, android:layout_height, android:maxWidth, android:maxHeight parameters. So you should use them for original image downscaling.

Do you mean "thumb" as Bitmap object or image file?

@bhavesh-hirpara
Copy link
Author

Yes.....I can set fix width and height for imageview.. but sometime I need thumb bitmap.

@nostra13
Copy link
Owner

Why?

@bhavesh-hirpara
Copy link
Author

for contact photo or elsewhere.

@nostra13
Copy link
Owner

I don't understand, do you need Bitmap reference or you want ImageView shows downscaled Bitmap, or something else?

@bhavesh-hirpara
Copy link
Author

i want downscaled bitmap.

@nostra13
Copy link
Owner

UIL downscales it for you depending on ImageView parameters. Final Bitmap size also depends on DisplayImageOptions.imageScaleType() option.

@nostra13
Copy link
Owner

Any questions?

@nostra13
Copy link
Owner

nostra13 commented Dec 6, 2012

7 days, no answer.

@nostra13 nostra13 closed this as completed Dec 6, 2012
@bhavesh-hirpara
Copy link
Author

sorry for inconvience. It's resolved.

@bhavesh-hirpara
Copy link
Author

Can I use your image loader for loading images from sdcard instead of live url???.. let me know.

@nostra13
Copy link
Owner

Of course.

@bhavesh-hirpara
Copy link
Author

if i will use sdcard path insted of url in imageLoader.displayImage(new File("myPath"), image12);, will work??

@nostra13
Copy link
Owner

Have you tried to read Readme or Java docs?
file:///mnt/sdcard/MyFolder/my_image.png

@bhavesh-hirpara
Copy link
Author

Yuap.. got it.

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

No branches or pull requests

3 participants