title: Gridview smooth scroll and image population from the system gallery
body: <p>I have created a gallery. I am populating a gridview from a simple cursor adapter (custom implementation). </p>
  
  <p>First issue is that gridview stucks in the middle while scrolling. I think its because images are binded to a view continuously on user interaction. How can I achieve a smooth scroll?</p>
  
  <p>Secondly I do not get all the images from the gallery through the Cursor. What do I need to do in order to get all the images. I also observed that this code does not return images on different devices, such as Samsung Galaxy s2. Works fine on Samsung Note 2 and Nexus 4 though. URI is same though: content://media/external/images/thumbnails</p>
  
  <p>Code for an adapter:</p>
  
  <pre><code>/**  
   * @author Syed Ahmed Hussain
   */
  public class CustomGalleryAdapter extends SimpleCursorAdapter {
  
      private ContentResolver mContentResolver;
      private LayoutInflater mLayoutInflater;
      private int mImageIdColumnIndex;
      private ImageView mImageView;
      private Context mContext;
      private int mLayout;
  
      public CustomGalleryAdapter(Context pContext, int pLayout, Cursor pCursor, String[] pFrom, int[] pTo, int pFlags) {
          super(pContext, pLayout, pCursor, pFrom, pTo, pFlags);
          mLayout             = pLayout;
          mContext            = pContext;
          mLayoutInflater     = LayoutInflater.from(mContext);
          mContentResolver    = mContext.getContentResolver();
          mImageIdColumnIndex = pCursor.getColumnIndex(MediaStore.Images.Thumbnails.IMAGE_ID);
      }
  
      @Override
      public View newView(Context pContext, Cursor pCursor, ViewGroup pParent) {
          return mLayoutInflater.inflate(mLayout, null);
      }
  
      @Override
      public void bindView(View pView, Context pContext, Cursor pCursor) {
          long id = pCursor.getLong(mImageIdColumnIndex);
          mImageView = (ImageView) pView;
          mImageView.setScaleType(ScaleType.CENTER_CROP);
          mImageView.setImageBitmap(MediaStore.Images.Thumbnails.getThumbnail(mContentResolver, id, MediaStore.Images.Thumbnails.MINI_KIND, new Options()));
      }
  
  }
  </code></pre>
  
  <p>Code for an activity: </p>
  
  <pre><code>public class GalleryActivity extends FragmentActivity implements LoaderManager.LoaderCallbacks&lt;Cursor&gt; {
  
      private String[] projection = { MediaStore.Images.Thumbnails.IMAGE_ID };
      private CustomGalleryAdapter mCustomGalleryAdapter;
      private String[] selectionArgs = null;
      private String selection = "";
      private GridView mGridView;
  
      @Override
      protected void onCreate(Bundle pSavedInstanceState) {
          super.onCreate(pSavedInstanceState);
          setContentView(R.layout.view_gallery);
          mGridView = (GridView) findViewById(R.id.gridView);
          getSupportLoaderManager().initLoader(0, null, this);
      }
  
      @Override
      public Loader&lt;Cursor&gt; onCreateLoader(int pId, Bundle pArgs) {
  
          return new android.support.v4.content.CursorLoader(getApplicationContext(), MediaStore.Images.Thumbnails.EXTERNAL_CONTENT_URI, null, null, null, null);
      }
  
      @Override
      public void onLoadFinished(Loader&lt;Cursor&gt; pLoader, Cursor pData) {
          mCustomGalleryAdapter = new CustomGalleryAdapter(getApplicationContext(), R.layout.gallery_item, pData, projection, new int[] { R.id.galleryImageView }, 0);
          mGridView.setAdapter(mCustomGalleryAdapter);
      }
  
      @Override
      public void onLoaderReset(Loader&lt;Cursor&gt; pLoader) {
  
      }
  
  }
  </code></pre>
  
  <p>View_Galler.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;GridView
      xmlns:android="http://schemas.android.com/apk/res/android"
      android:orientation="horizontal"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:layout_gravity="center"
      android:gravity="center"
      android:numColumns="auto_fit"
      android:columnWidth="100dp"
      android:paddingLeft="2dp"
      android:paddingRight="2dp"
      android:layoutMode="opticalBounds"
      android:verticalSpacing="10dp"
      android:horizontalSpacing="10dp"
      android:listSelector="#00000000"
      android:id="@+id/gridView" /&gt;
  </code></pre>
  
  <p>gallery_item.xml:</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;ImageView
    xmlns:android="http://schemas.android.com/apk/res/android"
    android:id="@+id/galleryImageView"
    android:layout_width="match_parent"
    android:layout_height="match_parent" /&gt;
  </code></pre>
  
  <p>Can anyone please guide me on what am I doing wrong? and how can I solve these problems?</p>