0

That is my code...

for(int i=0;i<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<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++;
    }

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.

can anyone help me.thanks in advance

Regards

arpit

user988853
  • 59
  • 1
  • 1
  • 5

1 Answers1

1

In your inner for loop which loops for 0,1 i.e 2 times.

In this inner loop you are adding same tr(tablerow) to tl(tablelayout) twice hence it is giving specified child has already parent warning.

You not manipulating ids variable properly hence you are getting toast for only 0,1,2, iv.setId(ids); Since inner loop repeats only twice check you ids variable.

Ashwin N Bhanushali
  • 3,872
  • 5
  • 39
  • 59
  • thanks for replay can i use tablerow array?i use same table row because i have show 2 images in one row... – user988853 Oct 11 '11 at 06:55
  • dont go for table row array do one thing add table row tr in table layout just after the inner for loop tl.addView(tr,new TableLayout.LayoutParams( LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT)); This will solve your prob. – Ashwin N Bhanushali Oct 11 '11 at 07:46
  • yes i did same thing and it's working thanks.do you know how can i add pdf file from url on android emulator?can you give me some link for that? – user988853 Oct 11 '11 at 09:01
  • Hit that url using Browser app of your Emulator and download will automatically start.Don't forget to have emulator with sdcard support – Ashwin N Bhanushali Oct 11 '11 at 09:08
  • can you check this link? http://stackoverflow.com/questions/7724009/open-pdf-file-from-url – user988853 Oct 11 '11 at 09:35