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 only loads when i scroll in ListView #35

Open
kingomar opened this issue Aug 14, 2013 · 1 comment
Open

Images only loads when i scroll in ListView #35

kingomar opened this issue Aug 14, 2013 · 1 comment

Comments

@kingomar
Copy link

Today, I was testing my application that uses a custom layout (with imageview inside) and I found out as soon as I scroll in listview, the listview lags then the image appears. Why? Is this an expected behaviour from imageloader when i'm loading images from a database? I am using almost the same code from LazyList.
Here is my code:

SamsungListView offlineadapter = new SamsungListView(ctx, c);
listview.setAdapter(offlineadapter);
SamsungListView Class:

public class SamsungListView extends CursorAdapter {

public com.androidarabia.lazylist.ImageLoader imageLoader;
LayoutInflater mLayoutInflater;
Cursor curs;
LebanonDatabase DbHelper;
ViewHolder holder;

public SamsungListView(Context context, Cursor c) {
    super(context, c);
    curs = c;
    mLayoutInflater = LayoutInflater.from(context);
    imageLoader = new com.androidarabia.lazylist.ImageLoader(
            context.getApplicationContext());
    DbHelper = new LebanonDatabase(context).open();
    holder = new ViewHolder();

}

static class ViewHolder {
    TextView title_text;
    TextView date_text;
    ImageView item_image;
    TextView del_image;
}

public View newView(Context context, Cursor cursor, ViewGroup parent) {
    View v = mLayoutInflater.inflate(R.layout.pricelist, parent, false);
    return v;
}

@Override
public void bindView(View v, Context context, Cursor c) {
    holder.title_text = (TextView) v.findViewById(R.id.title);
    holder.date_text = (TextView) v.findViewById(R.id.modelnumber);
    holder.item_image = (ImageView) v.findViewById(R.id.list_image);
    holder.del_image = (TextView) v.findViewById(R.id.details);

    final String title = c.getString(c
            .getColumnIndex(LebanonDatabase.KEY_PHONENAME));
    final String date = c.getString(c
            .getColumnIndex(LebanonDatabase.KEY_MODELNUMBER));

    final String imagePath = c.getString(c
            .getColumnIndex(LebanonDatabase.KEY_PRICE));

    final String deletion = c.getString(c
            .getColumnIndex(LebanonDatabase.KEY_URL));
    imageLoader.DisplayImage(deletion, holder.item_image);
    holder.title_text.setText(title);
    holder.del_image.setText(imagePath + " $");
    holder.date_text.setText(date);

}

Any suggestions? the listview sees some hiccups when i'm scrolling first time, but at second time everything is smooth.
i posted a topic on Stackoverflow http://goo.gl/T46dQO
Thank you for your time! this is the best repository for Android ever!

@thest1
Copy link
Owner

thest1 commented Aug 22, 2013

Probably your version of displayImage() method fetches image from database in UI thread. It should only be done in a separate thread.

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

No branches or pull requests

2 participants