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
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.