1

I have a ListView and a SimpleCursorAdapter. My code for the SimpleCursorAdapter looks like this:

private void listenAdapterErstellen()
{
    adapter = new SimpleCursorAdapter(this, R.layout.my_listlayout, 
            MainController.getInstance().getMyCursor(db), 
            new String[] {"Foo", "Test"}, 
            new int[] {R.id.imageViewFoo, R.id.textViewTest}, 0);

    adapter2.setViewBinder(new ViewBinder() {
        public boolean setViewValue(View view, Cursor cursor, int columnIndex) {
            if (columnIndex == 1) {
                ImageView imageView = (ImageView) view;

                String Pic = cursor.getString(1);
                if (Pic != null) {
                    File file = new File(Pic);
                    if (file.exists()) {
                        imageView.setImageBitmap(MainController.getInstance().generateBitmap(Pic, SessionActivity.this));
                    }
                } else {
                    imageView.setImageResource(R.drawable.ic_launcher);
                }
                return true;
            }
            if (columnIndex == 2) {
                ...
            }

            return false;
        }
    });
}

the problem is, that the my MainController.getInstance().generateBitmap() which generate a small bitmap takes a lot of time. So it takes some time until the list is loaded.

How can I generate the image for the list in the background and show the list instantly and then add the pictures?

gurehbgui
  • 14,236
  • 32
  • 106
  • 178
  • http://stackoverflow.com/questions/541966/how-do-i-do-a-lazy-load-of-images-in-listview try the thread in link. contains excellent source examples – Robert Rowntree Apr 30 '13 at 15:29
  • I need the stuff they do but not on a file in the internet but with a file on the device. anyway post this as a answer and I will accept it – gurehbgui Apr 30 '13 at 17:05

2 Answers2

1

This library work fine with images saved locally or in web: Universal Image Loader

andrehsouza
  • 479
  • 1
  • 5
  • 14
0

This thread contains a number of links to excellent source(github projects) that can become the generic approach to efficient list loaders of Bitmaps and images. I've had very good, efficient results with lazylist on a number of media intensive/ network intensive projects.

Community
  • 1
  • 1
Robert Rowntree
  • 6,230
  • 2
  • 24
  • 43