title: Handling Click Event of ImageView which is dynamically added
body: <p>Code : </p>
  
  <pre><code> maxIndex = alItemListDetails.size();
      linItemTags = (LinearLayout) findViewById(R.id.linItemTags);
      final ImageView image = new ImageView(this);
      for (int i = 0; i &lt; maxIndex; i++) {
          image.setLayoutParams(new android.view.ViewGroup.LayoutParams(80, 60));
          image.setMaxHeight(20);
          image.setMaxWidth(20);
          image.setTag(i);
          image.setImageResource(R.drawable.box);
          // Adds the view to the layout
          linItemTags.addView(image);
      }
      image.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              Common.displayToast(ItemDetailsActivity.this, "" + image.getTag());
          }
      });
  </code></pre>
  
  <p>As from the above code, you can see that I have generated imageview dynamically and trying to handle click event of that Imageview.</p>
  
  <p>But, It gives me errors as below : </p>
  
  <pre><code>Caused by: java.lang.IllegalStateException: The specified child already has a parent. You must call removeView() on the child's parent first.
  </code></pre>