I have a linear layout which I fill with imageviews everytime the user takes a picture with the camera. So these imageviews are added dynamically.
To each of these imageviews I attached an OnClick event to open the picture and show it in another imageview in another activity.
Each imageview has a tag containing an arraylist item with the bitmap information.
The OnClick event:
ImageView iv = new ImageView(this);
LayoutParams params = new LinearLayout.LayoutParams(LinearLayout.LayoutParams.WRAP_CONTENT, LinearLayout.LayoutParams.WRAP_CONTENT);
iv.setLayoutParams(params);
iv.setImageBitmap(mBitmap);
iv.setTag(pli);
iv.setPadding(5, 5, 5, 5);
lvp.setOnClickListener(new OnClickListener() {
public void onClick(View arg0) {
PhotoList pli = (PhotoList) arg0.getTag();
Intent i = new Intent(getBaseContext(), PhotoActivity.class);
i.putExtra("photo", pli.Photo);
i.putExtra("PhotoId", pli.id);
startActivity(i);
}
});
lvp.addView(iv);
Obviously the line with arg0.getTag() is not working.
Variable arg0 is of the linearlayout, but I need the clicked on imageview.
How do I detect wich imageview in the linearlayout was clicked on?
rg,
Eric
You have set the
OnClickListenerto the parentLinearLayoutinstead of theImageView.Instead of this:
Use this: