0

I have been trying to implement Lazy Loading of images in Android. I have followed this excellent tutorial here: http://www.androidhive.info/2012/02/android-custom-listview-with-image-and-text/

The problem is it works perfectly fine in the emulator. In emulator the images load up but on real devices they just display the default image.

I have tested it on 6 android devices with no luck but they load perfectly on Emulator.

Any ideas on where i am going wrong?

Thanks in advance guys!

Edit: I have modified the code to use JSON Parsing rather than XML Parsing, if that matters.

My Lazy Adapter class:

public class LazyAdapter extends BaseAdapter {

private Activity activity;
private ArrayList<HashMap<String, String>> data;
private static LayoutInflater inflater=null;
public ImageLoader imageLoader; 

public LazyAdapter(Activity a, ArrayList<HashMap<String, String>> d) {
    activity = a;
    data=d;
    inflater = (LayoutInflater)activity.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
    imageLoader=new ImageLoader(activity.getApplicationContext());
   // Toast.makeText(a, "here too", 500).show();
}

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

public Object getItem(int position) {
    return position;
}

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

public View getView(int position, View convertView, ViewGroup parent) {
    View vi=convertView;
    if(convertView==null)
        vi = inflater.inflate(R.layout.list_row, null);

    TextView title = (TextView)vi.findViewById(R.id.title); // title
    ImageView thumb_image=(ImageView)vi.findViewById(R.id.list_image); // thumb image

    HashMap<String, String> song = new HashMap<String, String>();
    song = data.get(position);

    // Setting all values in listview
    title.setText(song.get("msg"));

    imageLoader.DisplayImage(song.get("thumb"), thumb_image);
    return vi;
}
}
3
  • 1
    do you see any error/exception in logcat? Commented Oct 26, 2012 at 17:08
  • Nope bro, on emulator its working perfectly without any problems, but when i try on a real device it fails :( Commented Oct 26, 2012 at 17:14
  • 3
    I would say to post your LazyAdapter class so we can take a look. Not much else to go off of otherwise. You can try and execute some logging in the app for when it is on the device. Download a LogCat app and check to see if anything throws an error on the device.. Commented Oct 26, 2012 at 17:16

4 Answers 4

3

If you use this solution

https://github.com/thest1/LazyList

you need to add

android.permission.WRITE_EXTERNAL_STORAGE

in android manifest

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

1 Comment

This was the error, apparently the tutorial i was using also needed that permission & i totally forgot to see it !! Thanks a ton for pointing it out ! Weird though emulator loaded thumbs without that permission :P
3

Put this line in your code and try it ...

thumb_image.setTag(song.get("thumb"));
imageLoader.DisplayImage(song.get("thumb"), thumb_image);

Comments

1

the best answer I can give you is: "use other better implementations of lazy loading" such as fedorvlasov's lazy list adapter.

Comments

0

This is going to be a late answer but some can benefit. The tutorial you referenced is working very well on emulator and phones.

I think problem here was a permission issue.

if you dont put the following line to your manifest file, it works on Emulator but not on Phones.

<uses-permission android:name="android.permission.WRITE_EXTERNAL_STORAGE" />

Comments

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.