0

On the topic of my previous HERE I have managed to display the image in my listview. It turned out to not be using async in the process of displaying images, I felt heavy listview. I then tried to use the library Android Universal Image Loader. In my library usage is still a little confused trying to combine and replace the previous use ImageLoader library I use.

I put in onCreate in my Activity and my adapter :

File cacheDir = StorageUtils.getCacheDirectory(this.getApplicationContext());
        ImageLoaderConfiguration config = new ImageLoaderConfiguration.Builder(this.getApplicationContext())
            .memoryCacheExtraOptions(480, 800) // default = device screen dimensions
            .discCacheExtraOptions(480, 800, CompressFormat.JPEG, 75, null)
            .threadPoolSize(3) // default
            .threadPriority(Thread.NORM_PRIORITY - 1) // default
            .tasksProcessingOrder(QueueProcessingType.FIFO) // default
            .memoryCache(new LruMemoryCache(2 * 1024 * 1024))
            .memoryCacheSize(2 * 1024 * 1024)
            .memoryCacheSizePercentage(13) // default
            .discCache(new UnlimitedDiscCache(cacheDir)) // default
            .discCacheSize(50 * 1024 * 1024)
            .discCacheFileCount(100)
            .imageDownloader(new BaseImageDownloader(this.getApplicationContext())) // default
            .build();
        ImageLoader.getInstance().init(config);

In my loop (in onPostExecute) :

for (int i = 0; i < allData.length(); i++) {

    JSONObject c = allData.getJSONObject(i);

    // Storing each json item in variable
    String id = c.getString(Constants.TAG_MenuID);
    String title = c.getString(Constants.TAG_Title);
    String post = c.getString(Constants.TAG_Post);
    String image = c.getString(Constants.TAG_Image);

    BeritaBean mb = new BeritaBean();
    mb.setID(id);
    mb.setTitle(title);
    mb.setPost(post);
    mb.setImg(image);

    AmbilDataBean.add(mb);
}
adapter.setItem(AmbilDataBean);

Then I did also change my adapter of previous (using ImageLoader class) :

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

        View v = inflater.inflate(R.layout.list_row, null);

        ImageView img       = (ImageView) v.findViewById(R.id.image);
        TextView judul      = (TextView) v.findViewById(R.id.judul);
        TextView tanggal    = (TextView) v.findViewById(R.id.tanggal);
        TextView isi        = (TextView) v.findViewById(R.id.isi);

        BeritaBean obj      = (BeritaBean) getItem(position);

        judul.setText(obj.getTitle());
        tanggal.setText(obj.getCreated());
        isi.setText(obj.getPost());

        try {
            String urlImage = obj.getImg();
            if(urlImage.length() > 0){
                img.setTag(urlImage);
                imageLoader.DisplayImage(urlImage, img);
            }
        } catch (Exception e) {

        }
        return v;
    }

Became (using Universal Image Loader) on part :

try {
        String urlImage = obj.getImg();
        if(urlImage.length() > 0){
            img.setTag(urlImage);
            imageLoader.displayImage(urlImage, img);
        }
    } catch (Exception e) {

    }

But after my app run turns still images can not be displayed. Is there a setting that is lacking in this library? Please help

1 Answer 1

1

that seems a little bit like overkill - for a great library that uses async loading and handles listviews really well, check out koush's (well known dev) UrlImageViewHelper lib on github

Sign up to request clarification or add additional context in comments.

1 Comment

It's a very useful and easy to follow

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.