title: How to get Image(bitmap) from gridView
body: <p>I have gridView that load images from sdcard/dcim/camera and shows them.
  I want to put onclick listener on images and when I click on one it shoudl open that picture in other activity. How can I get image from gridView when I click on it.
  error is on this line:
  intent.putExtra("image", item.getImage()); 
  how can I fix this or how else can I make it work ?</p>
  
  <pre><code>    public class MainActivity extends Activity {
  
          ImageAdapter myImageAdapter;
  
          @Override
          public void onCreate(Bundle savedInstanceState) {
              super.onCreate(savedInstanceState);
              setContentView(R.layout.activity_main);
  
              GridView gridview = (GridView) findViewById(R.id.gridView);
              myImageAdapter = new ImageAdapter(this);
              gridview.setAdapter(myImageAdapter);
  
              gridview.setOnItemClickListener(new AdapterView.OnItemClickListener() {
                  public void onItemClick(AdapterView&lt;?&gt; parent, View v, int position, long id) {
                      ImageItem item = (ImageItem) parent.getItemAtPosition(position);
  
                      //Create intent
                      Intent intent = new Intent(MainActivity.this, DetailsActivity.class);
                      intent.putExtra("image", item.getImage()); // ERROR IS ON ITEM.GETIMAGE
  
                      //Start details activity
                      startActivity(intent);
                  }
              });
              String ExternalStorageDirectoryPath = Environment
                      .getExternalStorageDirectory()
                      .getAbsolutePath();
  
              String targetPath = ExternalStorageDirectoryPath + "/DCIM/Camera/";
  
              Toast.makeText(getApplicationContext(), targetPath, Toast.LENGTH_LONG).show();
              File targetDirector = new File(targetPath);
  
              File[] files = targetDirector.listFiles();
              for (File file : files){
                  myImageAdapter.add(file.getAbsolutePath());
              }
          }
  
      }
  </code></pre>
  
  <p>//*****************************************/ </p>
  
  <pre><code>public class ImageItem {
      private Bitmap image;
      private String title;
  
      public ImageItem(Bitmap image ) {
          super();
          this.image = image;
      }
  
      public Bitmap getImage() {
          return image;
      }
  
      public void setImage(Bitmap image) {
          this.image = image;
      }
  
      public String getTitle() {
          return title;
      }
  
      public void setTitle(String title) {
          this.title = title;
      }
  }
  </code></pre>
  
  <p>//****************************************************/</p>
  
  <pre><code>public class ImageAdapter extends BaseAdapter {
  
      private Context mContext;
      ArrayList&lt;String&gt; itemList = new ArrayList&lt;String&gt;();
  
      public ImageAdapter(Context c) {
          mContext = c;
      }
  
      void add(String path){
          itemList.add(path);
      }
  
      @Override
      public int getCount() {
          return itemList.size();
      }
  
      @Override
      public Object getItem(int arg0) {
          // TODO Auto-generated method stub
          return null;
      }
  
      @Override
      public long getItemId(int position) {
          // TODO Auto-generated method stub
          return 0;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          ImageView imageView;
          if (convertView == null) {  // if it's not recycled, initialize some attributes
              imageView = new ImageView(mContext);
              imageView.setLayoutParams(new GridView.LayoutParams(220, 220));
              imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
              imageView.setPadding(8, 8, 8, 8);
          } else {
              imageView = (ImageView) convertView;
          }
  
          Bitmap bm = decodeSampledBitmapFromUri(itemList.get(position), 220, 220);
  
          imageView.setImageBitmap(bm);
          return imageView;
      }
  
      public Bitmap decodeSampledBitmapFromUri(String path, int reqWidth, int reqHeight) {
  
          Bitmap bm = null;
          // First decode with inJustDecodeBounds=true to check dimensions
          final BitmapFactory.Options options = new BitmapFactory.Options();
          options.inJustDecodeBounds = true;
          BitmapFactory.decodeFile(path, options);
  
          // Calculate inSampleSize
          options.inSampleSize = calculateInSampleSize(options, reqWidth, reqHeight);
  
          // Decode bitmap with inSampleSize set
          options.inJustDecodeBounds = false;
          bm = BitmapFactory.decodeFile(path, options);
  
          return bm;
      }
  
      public int calculateInSampleSize(
  
              BitmapFactory.Options options, int reqWidth, int reqHeight) {
          // Raw height and width of image
          final int height = options.outHeight;
          final int width = options.outWidth;
          int inSampleSize = 1;
  
          if (height &gt; reqHeight || width &gt; reqWidth) {
              if (width &gt; height) {
                  inSampleSize = Math.round((float)height / (float)reqHeight);
              } else {
                  inSampleSize = Math.round((float)width / (float)reqWidth);
              }
          }
  
          return inSampleSize;
      }
  
  }
  </code></pre>
  
  <p>//***********************************************/</p>
  
  <pre><code>public class DetailsActivity extends Activity {
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.details_activity);
  
          Bitmap bitmap = getIntent().getParcelableExtra("image");
  
  
          ImageView imageView = (ImageView) findViewById(R.id.image1);
          imageView.setImageBitmap(bitmap);
      }
  }
  </code></pre>
  
  <p>//*******************************************************/</p>
  
  <p>activity_main.xml</p>
  
  <pre><code>&lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:background="#f0f0f0"&gt;
  
      &lt;GridView
          android:id="@+id/gridView"
          android:layout_width="fill_parent"
          android:layout_height="wrap_content"
          android:layout_margin="5dp"
          android:columnWidth="150dp"
          android:drawSelectorOnTop="true"
          android:gravity="center"
          android:numColumns="auto_fit"
          android:stretchMode="columnWidth"
          android:verticalSpacing="5dp"
          android:focusable="true"
          android:clickable="true"/&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p>//*************************************************/</p>
  
  <p>details_activity.xml</p>
  
  <pre><code>&lt;FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical"
      android:background="#000"&gt;
  
      &lt;ImageView
          android:id="@+id/image1"
          android:layout_width="match_parent"
          android:layout_height="match_parent"
          android:layout_gravity="center"
          android:scaleType="fitCenter" /&gt;
  
  
  &lt;/FrameLayout&gt;
  </code></pre>