title: how to make click listener for images in horizontal ScrollView
body: <p>I m making an horizontal Scroll View to display images in Android app.But i dont know how to make click listener for each individual images.My code is</p>
  
  <pre><code>    private Integer images[] = {R.drawable.mba, R.drawable.lifestylemin, 
  R.drawable.jee,R.drawable.comic,R.drawable.defence};
  // private ReaderView mReader;
  // ImageView imageGallery;
  LinearLayout im1;
  LinearLayout imageGallery;
  LinearLayout imageGallery2;
  ImageView imageView;
  public View onCreateView(LayoutInflater inflater, ViewGroup container, 
  Bundle savedInstanceState) {
  
      View view=inflater.inflate(R.layout.tab2, container, false);
      // init PlugPDF
      LinearLayout adcat=(LinearLayout)view.findViewById(R.id.adcat);
      adcat.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              startActivity(new Intent(getActivity(),ebookSelection.class));
          }
      });
  
       imageGallery = (LinearLayout) view.findViewById(R.id.imageGallery);
      imageGallery2 = (LinearLayout) view.findViewById(R.id.imageGallery2);
      addImagesToThegallery();
  
   //edit code
      for(int i=0;i&lt;images.length;i++){
      final ImageView imageView = (ImageView) getImageView(images[i]);
      imageView.setOnClickListener(new View.OnClickListener() {
      public void onClick(View v) {
          Intent i=new Intent(getActivity(),book.class);
          int id=imageView.getId();
          i.putExtra("id",id);
          startActivity(i);
      }
     });
     }
   ////
      return view;
  }
  private void addImagesToThegallery() {
  
      for (Integer image : images) {
          imageGallery.addView(getImageView(image));
          imageGallery2.addView(getImageView(image));
      }
  }
  
  
  private View getImageView(Integer image) {
      ImageView imageView = new  
    ImageView(getActivity().getApplicationContext());
      LinearLayout.LayoutParams lp = new LinearLayout.LayoutParams(260, 400);
      lp.setMargins(0, 0, 10, 0);
  
      imageView.setLayoutParams(lp);
      imageView.setImageResource(image);
      imageView.setScaleType(ImageView.ScaleType.FIT_XY);
      return imageView;
  }
  </code></pre>
  
  <p>I want to make individua click listener for each image so that i can perform different tast from different images.
  Thanxx in advance.</p>