title: Close DialogFragment on click
body: <p>I followed <a href="http://www.androidhive.info/2016/04/android-glide-image-library-building-image-gallery-app/" rel="nofollow noreferrer">this tutorial</a> (scroll down to the "<strong>Fullscreen Image Slideshow</strong>" section) to implement a fullscreen <code>DialogFragment</code> in order to create an image slideshow.</p>
  
  <p>How can I make it so that when the user clicks anywhere on the screen, it closes the <code>DialogFragment</code>?</p>
  
  <p>I tried to implement an <code>OnClickListener</code> (<a href="https://pastebin.com/QNBQUJn7" rel="nofollow noreferrer">code here</a>), but the click event never gets triggered.</p>
  
  <p>Here is the <code>DialogFragment</code> class from the tutorial:</p>
  
  <pre><code>public class SlideshowDialogFragment extends DialogFragment {
      private ArrayList&lt;Image&gt; images;
  
      private ViewPager viewPager;
  
      private MyViewPagerAdapter myViewPagerAdapter;
  
      private TextView lblCount, lblTitle, lblDate;
  
      private int selectedPosition = 0;
  
      static SlideshowDialogFragment newInstance() {
          SlideshowDialogFragment f = new SlideshowDialogFragment();
          return f;
      }
  
      @Override
      public View onCreateView(LayoutInflater inflater, ViewGroup container,
                               Bundle savedInstanceState) {
          View v = inflater.inflate(R.layout.fragment_image_slider, container, false);
          viewPager = (ViewPager) v.findViewById(R.id.viewpager);
          lblCount = (TextView) v.findViewById(R.id.lbl_count);
          lblTitle = (TextView) v.findViewById(R.id.title);
          lblDate = (TextView) v.findViewById(R.id.date);
  
          images = (ArrayList&lt;Image&gt;) getArguments().getSerializable("images");
          selectedPosition = getArguments().getInt("position");
  
          Log.e(TAG, "position: " + selectedPosition);
          Log.e(TAG, "images size: " + images.size());
  
          myViewPagerAdapter = new MyViewPagerAdapter();
          viewPager.setAdapter(myViewPagerAdapter);
          viewPager.addOnPageChangeListener(viewPagerPageChangeListener);
  
          setCurrentItem(selectedPosition);
  
          return v;
      }
  
      private void setCurrentItem(int position) {
          viewPager.setCurrentItem(position, false);
      }
  
      //  adapter
      public class MyViewPagerAdapter extends PagerAdapter {
  
          private LayoutInflater layoutInflater;
  
          public MyViewPagerAdapter() {
          }
  
          @Override
          public Object instantiateItem(ViewGroup container, int position) {
  
              layoutInflater = (LayoutInflater) getActivity().getSystemService(Context.LAYOUT_INFLATER_SERVICE);
              View view = layoutInflater.inflate(R.layout.image_fullscreen_preview, container, false);
  
              ImageView imageViewPreview = (ImageView) view.findViewById(R.id.image_preview);
  
              Image image = images.get(position);
  
              Glide.with(getActivity()).load(image.getLarge())
                      .thumbnail(0.5f)
                      .crossFade()
                      .diskCacheStrategy(DiskCacheStrategy.ALL)
                      .into(imageViewPreview);
  
              container.addView(view);
  
              return view;
          }
  
          @Override
          public int getCount() {
              return images.size();
          }
  
          @Override
          public boolean isViewFromObject(View view, Object obj) {
              return view == ((View) obj);
          }
  
  
          @Override
          public void destroyItem(ViewGroup container, int position, Object object) {
              container.removeView((View) object);
          }
      }
  }
  </code></pre>