The specified child already has a parent and click event
<p>That is my code...</p>

<pre><code>for(int i=0;i&lt;sitesList.getPdf().size();i++)
    {
        Bitmap bmp;
        URL url=null;
        InputStream is;
        ImageView iv=null;

        tr=new TableRow(this);
        tr.setLayoutParams(new LayoutParams(
                LayoutParams.WRAP_CONTENT,
                LayoutParams.WRAP_CONTENT));

        for (int j=0;j&lt;2;j++)
        {
            iv=new ImageView(this);
            try
            {
                s1=sitesList.getThumbnail().get(count);
                url = new URL(s1);
                count++;

                 conn=(HttpURLConnection)url.openConnection(); 
                 conn.setDoInput(true);
                 conn.connect();

                  is = conn.getInputStream();

                 bmp = BitmapFactory.decodeStream(is); 
                 iv.setImageBitmap(bmp);

                    iv.setLayoutParams(new LayoutParams(
                            LayoutParams.FILL_PARENT,
                            LayoutParams.FILL_PARENT));
                    iv.setId(ids);
                    int flag=iv.getId();
                    Log.v(".....Flag.....",+flag+"");

                    tr.addView(iv);

                    tl.addView(tr,new TableLayout.LayoutParams(
                            LayoutParams.FILL_PARENT,
                            LayoutParams.WRAP_CONTENT));

                    ids++;
                    Log.v(".....Counter...",count+"");
                    iv.setOnClickListener(new View.OnClickListener() 
                    {

                        public void onClick(View v) 
                        {


                            int a=v.getId();
                            if(a==0)
                            {
                                Toast.makeText(getApplicationContext(), "0",Toast.LENGTH_SHORT).show();
                            }
                            else if(a==1)
                            {
                                Toast.makeText(getApplicationContext(), "1",Toast.LENGTH_SHORT).show();
                            }
                            else if(a==2)
                            {
                                Toast.makeText(getApplicationContext(), "2",Toast.LENGTH_SHORT).show();
                            }
                            else if(a==3)
                            {
                                Toast.makeText(getApplicationContext(), "3",Toast.LENGTH_SHORT).show();
                            }
                            else if(a==4)
                            {
                                Toast.makeText(getApplicationContext(), "4",Toast.LENGTH_SHORT).show();
                            }
                            else if(a==5)
                            {
                                Toast.makeText(getApplicationContext(), "5",Toast.LENGTH_SHORT).show();
                            }

                        }
                    });     

            }catch(Exception e)
            {
                e.printStackTrace();
            }
        }

        //Log.v(".....Myids",ids+"");
        //ids++;
    }
</code></pre>

<p>it will show me (1)"The specified child already has a parent" warning 
and (2) when i click image it will recognize only 0,1,2 on the toast.</p>

<p>can anyone help me.thanks in advance</p>

<p>Regards</p>

<p>arpit</p>
