title: Creating a Gallery with GridView in Fragment?
body: <p>I am trying to create a Gallery with gridview in Fragment named GalleryFrag using below code</p>
  
  <pre><code>import android.content.Context;
  import android.os.Bundle;
  import android.support.v4.app.Fragment;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.widget.BaseAdapter;
  import android.widget.GridView;
  import android.widget.ImageView;
  
  import java.io.File;
  import java.util.ArrayList;
  
  
  /**
   * A simple {@link Fragment} subclass.
   */
  public class GalleryFrag extends Fragment {
      ArrayList&lt;String&gt; f = new ArrayList&lt;&gt;();
      File[] files;
  
      public GalleryFrag() {
          // Required empty public constructor
      }
  
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          // Inflate the layout for this fragment
          View view = inflater.inflate(R.layout.fragment_gallery, container, false);
          GridView gridView = (GridView) view.findViewById(R.id.gv);
          gridView.setAdapter(new ImageAdapter(this.getContext()));
          getImages();
          return view;
      }
  
      public void getImages() {
          File file = new File(android.os.Environment.getExternalStoragePublicDirectory(DIRECTORY_PICTURES));
          if (file.isDirectory()) {
              files = file.listFiles();
              for (int i = 0; i &lt; files.length; i++) {
                  f.add(files[i].getAbsolutePath());
              }
          }
      }
  
      public class ImageAdapter extends BaseAdapter {
          private Context mContext;
  
          public ImageAdapter(Context context) {
              mContext = context;
          }
  
          @Override
          public int getCount() {
              return f.size();
          }
  
          @Override
          public Object getItem(int position) {
              return position;
          }
  
          @Override
          public long getItemId(int position) {
              return position;
          }
  
          @Override
          public View getView(int position, View convertView, ViewGroup parent) {
              ImageView imageView;
              if (convertView == null) {
                  //if it's not recycled, initialize some atributes
                  imageView = new ImageView(mContext);
                  imageView.setLayoutParams(new ViewGroup.LayoutParams(85, 85));
                  imageView.setScaleType(ImageView.ScaleType.CENTER_CROP);
                  imageView.setPadding(8, 8, 8, 8);
              } else {
                  imageView = (ImageView) convertView;
              }
              imageView.setImageResource(Integer.parseInt(f.get(position)));
              return imageView;
          }
      }
  } 
  </code></pre>
  
  <p>But When I run the app it shows nothing in Gridview from the folder named Pictures which contains the images.
  I Want to show the image in full screen when the user clicks on any image in grid view.
  Can go with any different method too.
  Please help me to create the gallery for my app.
  Answers are really welcomed.</p>
  
  <p><strong>CodeUpdate</strong> 
  I used this code to check file.exists :</p>
  
  <pre><code>public void getImages() {
          File file = new File(String.valueOf(Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS)));
          if (file.exists()){
              Toast.makeText(this.getContext(), "Yep It's there", Toast.LENGTH_LONG).show();
              files = file.listFiles();
              if (files !=null) {
                  for (int i = 0; i &lt; files.length; i++) {
                      //String[] FileNames= new String[files.length];
                      //FileNames[i]=files[i].getName();
                      //ArrayAdapter&lt;String&gt; arrayAdapter = new ArrayAdapter&lt;&gt;(this.getContext(), android.R.layout.simple_list_item_1, FileNames);
                      //listView.setAdapter(arrayAdapter);
                      f.add(files[i].getAbsolutePath());
                  }
              } else {
                  Toast.makeText(this.getContext(), "error", Toast.LENGTH_SHORT).show();
              }
          }
      } 
  </code></pre>
  
  <p><strong>Update</strong>
  I Need to add subfolders too in the Gallery and And need to upgrade from grid to recyclerview. I need to show images onclick on full screen but on other activities instead in same fragment with popup image viewer.</p>