title: open image in fullscreen when it get clicked from grid view (fragments with sliding menu )
body: <p>Hello i am developing my first app and so far i am successful to get images from sd card and to display them in gridview. but its not showing me in full screen when i am clicking on image.
  i am working with the  fragments sliding menu. my app is getting force close whenever i tries to click on image.</p>
  
  <p>blow is my xml and java files.</p>
  
  <p><strong>GridViewactivity.java</strong></p>
  
  <pre><code>package com.Adz.mediaplus;
  
  import java.util.ArrayList;
  
  import android.content.res.Resources;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.util.TypedValue;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.GridView;
  
  public class GridViewActivity extends Fragment {
  
      private Utils utils;
      private ArrayList&lt;String&gt; imagePaths = new ArrayList&lt;String&gt;();
      private GridViewImageAdapter adapter;
      private GridView gridView;
      private int columnWidth;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
          View rootView = inflater.inflate(R.layout.activity_grid_view,
                  container, false);
          // Gridview adapter
          adapter = new GridViewImageAdapter(getActivity(), imagePaths,
                  columnWidth);
  
          // setting grid view adapter
          gridView.setAdapter(adapter);
          return rootView;
      }
  
      @Override
      public void onStart() {
          super.onStart();
  
          gridView = (GridView) getView().findViewById(R.id.grid_view);
  
          utils = new Utils(getActivity());
  
          // Initilizing Grid View
          InitilizeGridLayout();
  
          // loading all image paths from SD card
          imagePaths = utils.getFilePaths();
  
      }
  
      private void InitilizeGridLayout() {
          Resources r = getResources();
          float padding = TypedValue.applyDimension(TypedValue.COMPLEX_UNIT_DIP,
                  AppConstant.GRID_PADDING, r.getDisplayMetrics());
  
          columnWidth = (int) ((utils.getScreenWidth() - ((AppConstant.NUM_OF_COLUMNS + 1) * padding)) / AppConstant.NUM_OF_COLUMNS);
  
          gridView.setNumColumns(AppConstant.NUM_OF_COLUMNS);
          gridView.setColumnWidth(columnWidth);
          gridView.setStretchMode(GridView.NO_STRETCH);
          gridView.setPadding((int) padding, (int) padding, (int) padding,
                  (int) padding);
          gridView.setHorizontalSpacing((int) padding);
          gridView.setVerticalSpacing((int) padding);
      }
  
  }
  </code></pre>
  
  <p>GridViewAdepter.java</p>
  
  <pre><code>package com.Adz.mediaplus;
  
  
  import java.io.File;
  import java.io.FileInputStream;
  import java.io.FileNotFoundException;
  import java.util.ArrayList;
  
  import android.app.Activity;
  import android.content.Intent;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.view.View;
  import android.view.View.OnClickListener;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.GridView;
  import android.widget.ImageView;
  
  public class GridViewImageAdapter extends BaseAdapter {
  
      private Activity _activity;
      private ArrayList&lt;String&gt; _filePaths = new ArrayList&lt;String&gt;();
      private int imageWidth;
  
      public GridViewImageAdapter(Activity activity, ArrayList&lt;String&gt; filePaths,
              int imageWidth) {
          this._activity = activity;
          this._filePaths = filePaths;
          this.imageWidth = imageWidth;
      }
  
      @Override
      public int getCount() {
          return this._filePaths.size();
      }
  
      @Override
      public Object getItem(int position) {
          return this._filePaths.get(position);
      }
  
      @Override
      public long getItemId(int position) {
          return position;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
          ImageView imageView;
          if (convertView == null) {
              imageView = new ImageView(_activity);
          } else {
              imageView = (ImageView) convertView;
          }
  
          // get screen dimensions
          Bitmap image = decodeFile(_filePaths.get(position), imageWidth,
                  imageWidth);
  
          imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
          imageView.setLayoutParams(new GridView.LayoutParams(imageWidth,
                  imageWidth));
          imageView.setImageBitmap(image);
  
          // image view click listener
          imageView.setOnClickListener(new OnImageClickListener(position));
  
          return imageView;
      }
  
      class OnImageClickListener implements OnClickListener {
  
          int _postion;
  
          // constructor
          public OnImageClickListener(int position) {
              this._postion = position;
          }
  
          @Override
          public void onClick(View v) {
              // on selecting grid view image
              // launch full screen activity
              Intent i = new Intent(_activity, FullScreenViewActivity.class);
              i.putExtra("position", _postion);
              _activity.startActivity(i);
          }
  
      }
  
      /*
       * Resizing image size
       */
      public static Bitmap decodeFile(String filePath, int WIDTH, int HIGHT) {
          try {
  
              File f = new File(filePath);
  
              BitmapFactory.Options o = new BitmapFactory.Options();
              o.inJustDecodeBounds = true;
              BitmapFactory.decodeStream(new FileInputStream(f), null, o);
  
              final int REQUIRED_WIDTH = WIDTH;
              final int REQUIRED_HIGHT = HIGHT;
              int scale = 1;
              while (o.outWidth / scale / 2 &gt;= REQUIRED_WIDTH
                      &amp;&amp; o.outHeight / scale / 2 &gt;= REQUIRED_HIGHT)
                  scale *= 2;
  
              BitmapFactory.Options o2 = new BitmapFactory.Options();
              o2.inSampleSize = scale;
              return BitmapFactory.decodeStream(new FileInputStream(f), null, o2);
          } catch (FileNotFoundException e) {
              e.printStackTrace();
          }
          return null;
      }
  
  }
  </code></pre>
  
  <p><strong>FullScreenActivity.java</strong></p>
  
  <pre><code>package com.Adz.mediaplus;
  
  import android.app.Fragment;
  import android.content.Intent;
  import android.os.Bundle;
  import android.support.v4.view.ViewPager;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  
  public class FullScreenViewActivity extends Fragment {
  
      private Utils utils;
      private FullScreenImageAdapter adapter;
      private ViewPager viewPager;
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
              Bundle savedInstanceState) {
  
          View rootView = inflater.inflate(R.layout.activity_fullscreen_view,
                  container, false);
          return rootView;
      }
  
      @Override
      public void onStart() {
          super.onStart();
  
          viewPager = (ViewPager) getView().findViewById(R.id.pager);
  
          utils = new Utils(getActivity().getApplicationContext());
  
          Intent i = super.getActivity().getIntent(); 
          int position = i.getIntExtra("position", 0);
  
          adapter = new FullScreenImageAdapter(getActivity(),
                  utils.getFilePaths());
  
          viewPager.setAdapter(adapter);
  
          // displaying selected image first
          viewPager.setCurrentItem(position);
      }
  }
  </code></pre>
  
  <p><strong>FullScreenImageAdepter.java</strong></p>
  
  <pre><code>package com.Adz.mediaplus;
  
  
  import java.util.ArrayList;
  
  import android.app.Activity;
  import android.content.Context;
  import android.graphics.Bitmap;
  import android.graphics.BitmapFactory;
  import android.support.v4.view.PagerAdapter;
  import android.support.v4.view.ViewPager;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.Button;
  import android.widget.RelativeLayout;
  
  public class FullScreenImageAdapter extends PagerAdapter {
  
      private Activity _activity;
      private ArrayList&lt;String&gt; _imagePaths;
      private LayoutInflater inflater;
  
      // constructor
      public FullScreenImageAdapter(Activity activity,
              ArrayList&lt;String&gt; imagePaths) {
          this._activity = activity;
          this._imagePaths = imagePaths;
      }
  
      @Override
      public int getCount() {
          return this._imagePaths.size();
      }
  
      @Override
      public boolean isViewFromObject(View view, Object object) {
          return view == ((RelativeLayout) object);
      }
  
      @Override
      public Object instantiateItem(ViewGroup container, int position) {
          TouchImageView imgDisplay;
          Button btnClose;
  
          inflater = (LayoutInflater) _activity
                  .getSystemService(Context.LAYOUT_INFLATER_SERVICE);
          View viewLayout = inflater.inflate(R.layout.layout_fullscreen_image, container,
                  false);
  
          imgDisplay = (TouchImageView) viewLayout.findViewById(R.id.imgDisplay);
          btnClose = (Button) viewLayout.findViewById(R.id.btnClose);
  
          BitmapFactory.Options options = new BitmapFactory.Options();
          options.inPreferredConfig = Bitmap.Config.ARGB_8888;
          Bitmap bitmap = BitmapFactory.decodeFile(_imagePaths.get(position), options);
          imgDisplay.setImageBitmap(bitmap);
  
          // close button click event
          btnClose.setOnClickListener(new View.OnClickListener() {            
              @Override
              public void onClick(View v) {
                  _activity.finish();
              }
          }); 
  
          ((ViewPager) container).addView(viewLayout);
  
          return viewLayout;
      }
  
      @Override
      public void destroyItem(ViewGroup container, int position, Object object) {
          ((ViewPager) container).removeView((RelativeLayout) object);
  
      }
  
  }
  </code></pre>
  
  <p><strong>activity_fullscreen_view.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent"
      android:orientation="vertical" &gt;
  
      &lt;android.support.v4.view.ViewPager
          android:id="@+id/pager"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p><strong>layout_fullscreen_image.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="utf-8"?&gt;
  &lt;RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
      android:layout_width="match_parent"
      android:layout_height="match_parent" &gt;
  
      &lt;com.Adz.mediaplus.TouchImageView
          android:id="@+id/imgDisplay"
          android:layout_width="fill_parent"
          android:layout_height="fill_parent"
          android:scaleType="fitCenter" /&gt;
  
      &lt;Button
          android:id="@+id/btnClose"
          android:layout_width="wrap_content"
          android:layout_height="30dp"
          android:layout_alignParentRight="true"
          android:layout_alignParentTop="true"
          android:layout_marginRight="15dp"
          android:layout_marginTop="15dp"
          android:paddingTop="2dp"
          android:paddingBottom="2dp"
          android:background="@drawable/button_background"
          android:textColor="#ffffff"
          android:paddingLeft="10dp"
          android:paddingRight="10dp"
          android:text="Close" /&gt;
  
  &lt;/RelativeLayout&gt;
  </code></pre>
  
  <p><strong>Logcat</strong></p>
  
  <pre><code>   01-12 22:03:46.443: W/ResourceType(9872): No known package when getting value for resource number 0xffffffff
  01-12 22:03:46.443: W/ImageView(9872): Unable to find resource: -1
  01-12 22:03:46.443: W/ImageView(9872): android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
  01-12 22:03:46.443: W/ImageView(9872):  at android.content.res.Resources.getValue(Resources.java:1014)
  01-12 22:03:46.443: W/ImageView(9872):  at android.content.res.Resources.getDrawable(Resources.java:659)
  01-12 22:03:46.443: W/ImageView(9872):  at android.widget.ImageView.resolveUri(ImageView.java:616)
  01-12 22:03:46.443: W/ImageView(9872):  at android.widget.ImageView.onMeasure(ImageView.java:722)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.View.measure(View.java:15513)
  01-12 22:03:46.443: W/ImageView(9872):  at android.widget.RelativeLayout.measureChildHorizontal(RelativeLayout.java:645)
  01-12 22:03:46.443: W/ImageView(9872):  at android.widget.RelativeLayout.onMeasure(RelativeLayout.java:425)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.View.measure(View.java:15513)
  01-12 22:03:46.443: W/ImageView(9872):  at android.widget.ListView.setupChild(ListView.java:1909)
  01-12 22:03:46.443: W/ImageView(9872):  at android.widget.ListView.makeAndAddView(ListView.java:1834)
  01-12 22:03:46.443: W/ImageView(9872):  at android.widget.ListView.fillDown(ListView.java:674)
  01-12 22:03:46.443: W/ImageView(9872):  at android.widget.ListView.fillSpecific(ListView.java:1332)
  01-12 22:03:46.443: W/ImageView(9872):  at android.widget.ListView.layoutChildren(ListView.java:1630)
  01-12 22:03:46.443: W/ImageView(9872):  at android.widget.AbsListView.onLayout(AbsListView.java:1994)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.View.layout(View.java:14003)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.ViewGroup.layout(ViewGroup.java:4375)
  01-12 22:03:46.443: W/ImageView(9872):  at android.support.v4.widget.DrawerLayout.onLayout(DrawerLayout.java:714)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.View.layout(View.java:14003)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.ViewGroup.layout(ViewGroup.java:4375)
  01-12 22:03:46.443: W/ImageView(9872):  at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.View.layout(View.java:14003)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.ViewGroup.layout(ViewGroup.java:4375)
  01-12 22:03:46.443: W/ImageView(9872):  at android.widget.LinearLayout.setChildFrame(LinearLayout.java:1663)
  01-12 22:03:46.443: W/ImageView(9872):  at android.widget.LinearLayout.layoutVertical(LinearLayout.java:1521)
  01-12 22:03:46.443: W/ImageView(9872):  at android.widget.LinearLayout.onLayout(LinearLayout.java:1434)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.View.layout(View.java:14003)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.ViewGroup.layout(ViewGroup.java:4375)
  01-12 22:03:46.443: W/ImageView(9872):  at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  01-12 22:03:46.443: W/ImageView(9872):  at android.os.Handler.dispatchMessage(Handler.java:92)
  01-12 22:03:46.443: W/ImageView(9872):  at android.os.Looper.loop(Looper.java:137)
  01-12 22:03:46.443: W/ImageView(9872):  at android.app.ActivityThread.main(ActivityThread.java:5039)
  01-12 22:03:46.443: W/ImageView(9872):  at java.lang.reflect.Method.invokeNative(Native Method)
  01-12 22:03:46.443: W/ImageView(9872):  at java.lang.reflect.Method.invoke(Method.java:511)
  01-12 22:03:46.443: W/ImageView(9872):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  01-12 22:03:46.443: W/ImageView(9872):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  01-12 22:03:46.443: W/ImageView(9872):  at dalvik.system.NativeStart.main(Native Method)
  01-12 22:03:46.443: W/ResourceType(9872): No known package when getting value for resource number 0xffffffff
  01-12 22:03:46.443: W/ImageView(9872): Unable to find resource: -1
  01-12 22:03:46.443: W/ImageView(9872): android.content.res.Resources$NotFoundException: Resource ID #0xffffffff
  01-12 22:03:46.443: W/ImageView(9872):  at android.content.res.Resources.getValue(Resources.java:1014)
  01-12 22:03:46.443: W/ImageView(9872):  at android.content.res.Resources.getDrawable(Resources.java:659)
  01-12 22:03:46.443: W/ImageView(9872):  at android.widget.FrameLayout.onLayout(FrameLayout.java:448)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.View.layout(View.java:14003)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.ViewGroup.layout(ViewGroup.java:4375)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.ViewRootImpl.performLayout(ViewRootImpl.java:1892)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.ViewRootImpl.performTraversals(ViewRootImpl.java:1711)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.ViewRootImpl.doTraversal(ViewRootImpl.java:989)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.ViewRootImpl$TraversalRunnable.run(ViewRootImpl.java:4351)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.Choreographer$CallbackRecord.run(Choreographer.java:749)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.Choreographer.doCallbacks(Choreographer.java:562)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.Choreographer.doFrame(Choreographer.java:532)
  01-12 22:03:46.443: W/ImageView(9872):  at android.view.Choreographer$FrameDisplayEventReceiver.run(Choreographer.java:735)
  01-12 22:03:46.443: W/ImageView(9872):  at android.os.Handler.handleCallback(Handler.java:725)
  01-12 22:03:46.443: W/ImageView(9872):  at android.os.Handler.dispatchMessage(Handler.java:92)
  01-12 22:03:46.443: W/ImageView(9872):  at android.os.Looper.loop(Looper.java:137)
  01-12 22:03:46.443: W/ImageView(9872):  at android.app.ActivityThread.main(ActivityThread.java:5039)
  01-12 22:03:46.443: W/ImageView(9872):  at java.lang.reflect.Method.invokeNative(Native Method)
  01-12 22:03:46.443: W/ImageView(9872):  at java.lang.reflect.Method.invoke(Method.java:511)
  01-12 22:03:46.443: W/ImageView(9872):  at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  01-12 22:03:46.443: W/ImageView(9872):  at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  01-12 22:03:46.443: W/ImageView(9872):  at dalvik.system.NativeStart.main(Native Method)
  01-12 22:03:46.443: W/Trace(9872): Unexpected value from nativeGetEnabledTags: 0
  01-12 22:03:47.723: W/Trace(9872): Unexpected value from nativeGetEnabledTags: 0
  01-12 22:03:47.723: W/Trace(9872): Unexpected value from nativeGetEnabledTags: 0
  01-12 22:03:47.723: D/AndroidRuntime(9872): Shutting down VM
  01-12 22:03:47.723: W/dalvikvm(9872): threadid=1: thread exiting with uncaught exception (group=0xb5dd2908)
  01-12 22:03:47.723: E/AndroidRuntime(9872): FATAL EXCEPTION: main
  01-12 22:03:47.723: E/AndroidRuntime(9872): android.content.ActivityNotFoundException: Unable to find explicit activity class {com.Adz.mediaplus/com.Adz.mediaplus.FullScreenViewActivity}; have you declared this activity in your AndroidManifest.xml?
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at android.app.Instrumentation.checkStartActivityResult(Instrumentation.java:1618)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at android.app.Instrumentation.execStartActivity(Instrumentation.java:1417)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at android.app.Activity.startActivityForResult(Activity.java:3370)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at android.app.Activity.startActivityForResult(Activity.java:3331)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at android.app.Activity.startActivity(Activity.java:3566)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at android.app.Activity.startActivity(Activity.java:3534)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at com.Adz.mediaplus.GridViewImageAdapter$OnImageClickListener.onClick(GridViewImageAdapter.java:87)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at android.view.View.performClick(View.java:4202)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at android.view.View$PerformClick.run(View.java:17340)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at android.os.Handler.handleCallback(Handler.java:725)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at android.os.Handler.dispatchMessage(Handler.java:92)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at android.os.Looper.loop(Looper.java:137)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at android.app.ActivityThread.main(ActivityThread.java:5039)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at java.lang.reflect.Method.invokeNative(Native Method)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at java.lang.reflect.Method.invoke(Method.java:511)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:793)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:560)
  01-12 22:03:47.723: E/AndroidRuntime(9872):     at dalvik.system.NativeStart.main(Native Method)
  </code></pre>