Displaying pictures stored on the SD Card using a Gridview
<p>I am relatively new to android and I really need help with this one. I am trying to write some code that will display the pictures on the sd card using a GridView, but so far when I run the application only the textview at the top is shown. I would like to know if there is a serious flaw in the logic of my code in the Main Activity code, Image Adapter class code or both. This is my code:</p>

<pre><code>package com.newtestforsdcarddisplay;

import android.app.Activity;
import android.os.Bundle;
import android.database.Cursor;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.view.View;
import android.widget.GridView;
import android.widget.AdapterView;
import android.widget.Toast;
import android.provider.MediaStore;
import android.provider.MediaStore.Images.Thumbnails;
import android.net.Uri;
import android.widget.AdapterView.OnItemClickListener;


public class MainActivity extends Activity {

public Cursor myImageCursor;
public int columnNumber;



/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);

String[] imageIDs = new String[]{Thumbnails._ID};

Uri myImagesSource = MediaStore.Images.Media.EXTERNAL_CONTENT_URI;

myImageCursor = managedQuery(myImagesSource, 
                imageIDs, null, null, MediaStore.Images.Thumbnails._ID);

         columnNumber = myImageCursor.getColumnIndexOrThrow(MediaStore.Images.Media._ID);

    GridView PhoneImageView = (GridView)findViewById(R.id.sdcard);
    PhoneImageView.setAdapter(new ImageAdapter(this));

    PhoneImageView.setOnItemClickListener(new OnItemClickListener() {
         public void onItemClick(AdapterView&lt;?&gt; parent, View v,
int position, long id) {



              String[] data = { MediaStore.Images.Media.DATA };

             Cursor  viewImageCursor = managedQuery(
MediaStore.Images.Media.EXTERNAL_CONTENT_URI, data,
null, null, MediaStore.Images.Thumbnails._ID );
           int imageColumnIndex = viewImageCursor.getColumnIndexOrThrow(MediaStore.Images.Media.DATA);
       viewImageCursor.moveToPosition(position);
       viewImageCursor.moveToFirst();
       String filepath = viewImageCursor.getString(imageColumnIndex);
       Toast.makeText(MainActivity.this, filepath, Toast.LENGTH_LONG).show();

      Bitmap yourSelectedImage = BitmapFactory.decodeFile(filepath);

      }
   });

}       
}
</code></pre>

<hr>

<pre><code>package com.newtestforsdcarddisplay;



import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.net.Uri;
import android.provider.MediaStore;

public class ImageAdapter extends BaseAdapter{

    final   MainActivity pca = new MainActivity();



    private Context context;

    public ImageAdapter(Context localContext) {
      //  context = localContext;
    }

    public int getCount() {
       // return pca.myImageCursor.getCount();
        return 0;
    }
    public Object getItem(int position) {
        return position;
    }
    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView picturesView;
        if (convertView == null) {
            picturesView = new ImageView(context);
            // Move cursor to current position
            pca.myImageCursor.moveToPosition(position);
            // Get the current value for the requested column
            int imageID = pca.myImageCursor.getInt(pca.columnNumber);
            // Set the content of the image based on the provided URI
            picturesView.setImageURI(Uri.withAppendedPath(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + imageID));
            picturesView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            picturesView.setPadding(8, 8, 8, 8);
            picturesView.setLayoutParams(new GridView.LayoutParams(100, 100));
        }
        else {
            picturesView = (ImageView)convertView;
        }
        return picturesView;
    }   



}


package com.newtestforsdcarddisplay;



import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.GridView;
import android.widget.ImageView;
import android.net.Uri;
import android.provider.MediaStore;

public class ImageAdapter extends BaseAdapter{

    final   MainActivity pca = new MainActivity();



    private Context context;

    public ImageAdapter(Context localContext) {
      //  context = localContext;
    }

    public int getCount() {
       // return pca.myImageCursor.getCount();
        return 0;
    }
    public Object getItem(int position) {
        return position;
    }
    public long getItemId(int position) {
        return position;
    }

    public View getView(int position, View convertView, ViewGroup parent) {
        ImageView picturesView;
        if (convertView == null) {
            picturesView = new ImageView(context);
            // Move cursor to current position
            pca.myImageCursor.moveToPosition(position);
            // Get the current value for the requested column
            int imageID = pca.myImageCursor.getInt(pca.columnNumber);
            // Set the content of the image based on the provided URI
            picturesView.setImageURI(Uri.withAppendedPath(
                    MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "" + imageID));
            picturesView.setScaleType(ImageView.ScaleType.FIT_CENTER);
            picturesView.setPadding(8, 8, 8, 8);
            picturesView.setLayoutParams(new GridView.LayoutParams(100, 100));
        }
        else {
            picturesView = (ImageView)convertView;
        }
        return picturesView;
    }   



}
</code></pre>

<hr>

<pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
&lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
    android:orientation="vertical"
    android:layout_width="fill_parent"
    android:layout_height="fill_parent"
    &gt;
&lt;TextView  
    android:layout_width="fill_parent" 
    android:layout_height="wrap_content" 
    android:text="@string/hello"
    /&gt;
    &lt;GridView  
    android:id="@+id/sdcard"
    android:layout_width="fill_parent" 
    android:layout_height="fill_parent"
    android:padding="10dp"
    android:verticalSpacing="10dp"
    android:horizontalSpacing="10dp"
    android:numColumns="auto_fit"
    android:columnWidth="90dp"
    android:stretchMode="columnWidth"
    android:gravity="center"
/&gt;


&lt;/LinearLayout&gt;
</code></pre>

<p>Could somebody help me please???? As I said before, I am fairly new to android and I have been struggling with this for a really long time. Any help would VERY MUCH appreciated.</p>
