Adnan Mulla
Adnan Mulla

Reputation: 2866

lazy loading in android works only on emulator?

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;
}
}

Upvotes: 0

Views: 1320

Answers (4)

Salahi Halil Altıncı
Salahi Halil Altıncı

Reputation: 545

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" />

Upvotes: 0

Stipe
Stipe

Reputation: 36

If you use this solution

https://github.com/thest1/LazyList

you need to add

android.permission.WRITE_EXTERNAL_STORAGE

in android manifest

Upvotes: 3

thepoosh
thepoosh

Reputation: 12587

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

Upvotes: 1

AndroidLearner
AndroidLearner

Reputation: 4636

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

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

Upvotes: 3

Related Questions