AQuery (Android Query) How to load images actually

6.3k views Asked by At

I am currently using Android Query library for image loading from server.

MAIN PROB: I want to store images first time and then after i want to load images from cache. I have seen here options for Cache Control using memCache and fileCache But i didn't get which is better to use for slow Internet connection and minimum Memory usage.

I have probably following solution with some confusion:

First of all i have used like this:( memCache and fileCache both true)

aq.id(holder.prodImage).image(holder.prodImagePath, true, true, 0, R.drawable.no_image, aq.getCachedImage(R.drawable.no_image), AQuery.FADE_IN);

But Here he has said that if image is huge, avoid memory caching

But i got problem while network is slow and memory is not sufficient

then after i have tried Delay Image Loading:

if(aq.shouldDelay(position, convertView, parent, holder.prodImagePath)){
    aq.id(holder.prodImage).image(R.drawable.no_image);
} else {
    aq.id(holder.prodImage).progress(view.findViewById(R.id.progressBar1)).image(holder.prodImagePath, false, true, 0, 0, null, AQuery.FADE_IN);
}

But its throwing NullPointerException like following:

12-10 12:11:26.492: E/AndroidRuntime(23309): java.lang.NullPointerException
12-10 12:11:26.492: E/AndroidRuntime(23309):    at com.androidquery.util.Common.shouldDelay(Common.java:328)
12-10 12:11:26.492: E/AndroidRuntime(23309):    at com.androidquery.util.Common.shouldDelay(Common.java:340)
12-10 12:11:26.492: E/AndroidRuntime(23309):    at com.androidquery.AbstractAQuery.shouldDelay(AbstractAQuery.java:2389)
12-10 12:11:26.492: E/AndroidRuntime(23309):    at com.salesman.fragments.ProductFragment$MyGridViewAdapter.getView(ProductFragment.java:423)
12-10 12:11:26.492: E/AndroidRuntime(23309):    at android.widget.AbsListView.obtainView(AbsListView.java:2477)
12-10 12:11:26.492: E/AndroidRuntime(23309):    at android.widget.GridView.makeAndAddView(GridView.java:1331)
12-10 12:11:26.492: E/AndroidRuntime(23309):    at android.widget.GridView.makeRow(GridView.java:331)
12-10 12:11:26.492: E/AndroidRuntime(23309):    at android.widget.GridView.fillDown(GridView.java:283)
12-10 12:11:26.492: E/AndroidRuntime(23309):    at android.widget.GridView.fillGap(GridView.java:243)
12-10 12:11:26.492: E/AndroidRuntime(23309):    at android.widget.AbsListView.trackMotionScroll(AbsListView.java:5549)
12-10 12:11:26.492: E/AndroidRuntime(23309):    at android.widget.AbsListView$FlingRunnable.run(AbsListView.java:4693)

what can i do and how i used this library for this simple problem

Please give me Solution.

Your Help would be Appreciated.

1

There are 1 answers

2
Pratik Butani On BEST ANSWER

Finally got the solution with following code:

/* Settings of Image */
//set the max number of concurrent network connections, default is 4
AjaxCallback.setNetworkLimit(8);

//set the max number of icons (image width <= 50) to be cached in memory, default is 20
BitmapAjaxCallback.setIconCacheLimit(50);

//set the max number of images (image width > 50) to be cached in memory, default is 20
BitmapAjaxCallback.setCacheLimit(50);

aq = new AQuery(context);

/* Getting Images from Server and stored in cache */
aq.id(holder.prodImageView).progress(convertView.findViewById(R.id.progressBar1)).image(holder.prodImagePath, true, true, 0, R.drawable.no_image, null, AQuery.FADE_IN);

Comment here if you didn't get and have any problem.

Thanks.