Custom GridView with a CursorAdapter

All your problems with Audio, Video and Images.

Custom GridView with a CursorAdapter

Postby Unicate » Wed Sep 15, 2010 6:18 pm

Hi all!

I need a GridView where I can load all my Thumbnails in. Easy, so far.
now I am extending the CursorAdapter and give it the following Cursor:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. Cursor c = getContentResolver().query(MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, null, null, null, null);
  2. grid.setAdapter(new ImageAdapter(this, c));
  3.  
Parsed in 0.030 seconds, using GeSHi 1.0.8.4

In the ImageAdapter I have to implement "newView" and "bindView"
I wrote a method "fillView" that I can use in both of them:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         private View fillView(View view, Cursor cursor) {
  2.                 String path = cursor.getString(cursor.getColumnIndex(MediaStore.Images.Thumbnails.DATA));
  3.                 long id = cursor.getLong(cursor.getColumnIndex(MediaStore.Images.Thumbnails.IMAGE_ID));
  4.                 ImageView image = (ImageView)view.findViewById(R.id.image);
  5.  
  6.                 image.setImageDrawable(Drawable.createFromPath(path));
  7.                 view.setLayoutParams(params);
  8.                 view.setPadding(2, 2, 2, 2);
  9.                 return view;
  10.         }
  11.  
Parsed in 0.032 seconds, using GeSHi 1.0.8.4


The Problem:
It takes WAY too long till the Images are loaded.
Is there any way to accelerate the whole Imageloading?
How do they do that in the Galeryapp?

Here the bindView and newView, if thats of any interest:
Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.         @Override
  2.         public void bindView(View view, Context context, Cursor cursor) {
  3.                 fillView(view, cursor);
  4.         }
  5.  
  6.         @Override
  7.         public View newView(Context context, Cursor cursor, ViewGroup parent) {
  8.                 LayoutInflater inflater = LayoutInflater.from(context);
  9.                 View view = inflater.inflate(R.layout.single_image, parent, false);
  10.                 return fillView(view, getCursor());
  11.         }
  12.  
Parsed in 0.036 seconds, using GeSHi 1.0.8.4



PS: I need a SDK 3 Solution!
Unicate
Junior Developer
Junior Developer
 
Posts: 10
Joined: Thu Sep 02, 2010 8:23 am

Top

Return to Multimedia Problems

Who is online

Users browsing this forum: No registered users and 10 guests