title: Android ViewPager onClickListener reacts even if other fragment is show
body: <p>I have a ViewPager which holds two fragments. one <code>fragment</code> contains nothing and the other <code>fragment</code> contains a <code>gridview</code> with <code>ImageViews</code>. 
  The <code>ImageViews</code> have a <code>onClickListener</code> set.
  Everything works fine so far... but when i am on the fragment which contains nothing and tap somewhere the onClickListener of the other fragments gridviews imagview reacts to my click even if its elements aren't visible.</p>
  
  <p>I could change my <code>onClickListener</code> so that it checks which fragment is shown but is that really the way i should do it ??? it feels a bit dirty </p>
  
  <p>This is my FragmentStatePageAdapter</p>
  
  <pre><code>public class OwnPagerAdapter extends FragmentStatePagerAdapter{
  
  private BackgroundImage backgroundImage = new BackgroundImage();
  private Apps apps = new Apps();
  private Home_Screen ac;
  
  public OwnPagerAdapter(FragmentManager fm, Home_Screen activity) {
      super(fm);
      this.ac = activity;
  }
  
  @Override
  public Fragment getItem(int position) {
      if(position == 0) {
      return backgroundImage;
      }else if(position == 1) {
  
          return  this.apps;
      }
      return null;
  }
  
  @Override
  public int getCount() {
      return 2;
  }
  }
  </code></pre>
  
  <p>This is my BaseAdapter</p>
  
  <pre><code>public class AppAdapter extends BaseAdapter {
  private AppLauncher launcherListener = new AppLauncher();
  private ArrayList&lt;ApplicationInfo&gt; appList;
  private Context ctx;
  public AppAdapter(ArrayList&lt;ApplicationInfo&gt; listOfApps, Context ctx){
      this.appList = listOfApps;
      this.ctx = ctx;
  }
  
  @Override
  public int getCount() {
      return this.appList.size();
  }
  
  @Override
  public Object getItem(int i) {
      ImageView v = new ImageView(this.ctx);
      v.setImageDrawable(this.appList.get(i).loadIcon(this.ctx.getPackageManager()));
      return v;
  }
  
  @Override
  public long getItemId(int i) {
      return 0;
  }
  
  @Override
  public View getView(final int i, View view, ViewGroup viewGroup) {
      if(view != null){
          ((ImageView) view).setImageDrawable(this.appList.get(i).loadIcon(this.ctx.getPackageManager()));
          view.setTag(i);
  
          return view;
      }
  
      ImageView v = new ImageView(this.ctx);
  
      v.setImageDrawable(this.appList.get(i).loadIcon(this.ctx.getPackageManager()));
      v.setScaleType(ImageView.ScaleType.CENTER);
      v.setOnClickListener(launcherListener);
      v.setTag(i);
      return v;
  
  }
  
  
  
  private class AppLauncher implements View.OnClickListener {
  
      @Override
      public void onClick(View view) {
  
          ctx.startActivity(ctx.getPackageManager().getLaunchIntentForPackage(appList.get((int) view.getTag()).packageName));
      }
  }
  }
  </code></pre>
  
  <p>Thats my fragment class</p>
  
  <pre><code>public class Apps extends Fragment implements LoaderManager.LoaderCallbacks&lt;ArrayList&lt;ApplicationInfo&gt;&gt;{
  
  
  private GridView gridview;
  @Override
  public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
      getLoaderManager().initLoader(1, null, this).forceLoad();
      View rootView = inflater.inflate(R.layout.fragment_apps, container, false);
      this.gridview = (GridView)rootView.findViewById(R.id.apptable);
  
      return rootView;
  
  
  }
  
  @Override
  public Loader&lt;ArrayList&lt;ApplicationInfo&gt;&gt; onCreateLoader(int id, Bundle args) {
      return new AppLoader(getActivity());
  }
  
  @Override
  public void onLoadFinished(Loader&lt;ArrayList&lt;ApplicationInfo&gt;&gt; loader, ArrayList&lt;ApplicationInfo&gt; data) {
      Toast.makeText(getActivity(), "Done with loading Apps", Toast.LENGTH_LONG).show();
      this.gridview.setAdapter(new AppAdapter(data,getActivity()));
  }
  
  @Override
  public void onLoaderReset(Loader&lt;ArrayList&lt;ApplicationInfo&gt;&gt; loader) {
  
  }
  }
  </code></pre>