David.C
David.C

Reputation: 21

Android - gridview scrolling issue (very slow scroll)

It's my first app so i am not use to code on java.

I have a gridview wich display thumbnails from the sdcard, but i can't have a smooth scroll.

If I put the /* Treatment part*/ out of the if the scroll is like i want but they are duplicate content and a part of the pics are not displayed.

Here is my code:

-Activity:

        GridView gridview = (GridView) findViewById(R.id.gridview1);
     String[] projection = {MediaStore.Images.Media._ID};
     String path ="/mnt/sdcard/Pictures";
     // Create the cursor pointing to the SDCard
     cursor = managedQuery( MediaStore.Images.Media.EXTERNAL_CONTENT_URI,
             projection, 
             //MediaStore.Images.Media.DATA + " like ? ",
             //new String[] {"%Pictures%Sopi%"},  
             "_data LIKE '%" + path  + "/%'",                
             null,
             MediaStore.Images.Media._ID);

    // Get the column index of the Media Image ID
    columnIndex = cursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);

    gridview.setAdapter(new ImageAdapterTest(RoomRawActivity.this));

-imageAdapater (get view):

public View getView(int position, View convertView, ViewGroup parent) {

    Log.v("adapter - getView","getView start!!");
    //Toast.makeText(mContext, "getView start!!"+position, 0).show();

    //Move cursor to current position
    RoomRawActivity.cursor.moveToPosition(position);

    ImageView picturesView;

    if (convertView == null) {

        picturesView = new ImageView(mContext);

            /* treatment */

// Get the current value for the requested column
int imageID = RoomRawActivity.cursor.getInt(RoomRawActivity.columnIndex);
// obtain the image URI
Uri uri = Uri.withAppendedPath( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, Integer.toString(imageID) );
String url = uri.toString();

//Set the content of the image based on the image URI
int originalImageId = Integer.parseInt(url.substring(url.lastIndexOf("/") + 1,   url.length()));
Bitmap b = MediaStore.Images.Thumbnails.getThumbnail(mContext.getContentResolver(),
         originalImageId, 
         MediaStore.Images.Thumbnails.MINI_KIND, 
         null);
        picturesView.setPadding(5, 5, 5, 5);
        picturesView.setBackgroundResource(R.drawable.border_grid_pics);

        picturesView.setImageBitmap(b);

        picturesView.setScaleType(ImageView.ScaleType.FIT_XY);
            /* END  treatment */
        }
    }else{
        picturesView = (ImageView) convertView;   
    }



    return picturesView;
}

Many Thanks! David.

Upvotes: 2

Views: 7132

Answers (1)

roxX
roxX

Reputation: 156

You should tidy up your GetView method such as;

  • you should NOT set your image resource on getView, use AsyncTask
  • try not to use SET SCALE on imageViews for performance

Looking this links might be useful;

Use AsyncTask to Load Bitmap Images

http://developer.android.com/training/improving-layouts/smooth-scrolling.html http://www.programmingmobile.com/2012/03/buttery-smooth-list-scrolling-in.html

Upvotes: 5

Related Questions