這是我的代碼...指定的孩子已經有一個父和點擊事件
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++;
}
它會告訴我的(1)「指定的孩子已經有一個父」警告 和(2)當我點擊圖片就會在烤麪包上只識別0,1,2。
誰能幫助me.thanks提前
問候
arpit
把你的堆棧追蹤。 – blessenm