Take an Integer array with an image, for example _view = new ImageView[size]; and inside forloop , initialize and set the tag in imageview, and then when processing the click event, get a tag of type int k = (Integer) v.getTag(); so as to get an exact click of your view.
ImageView _view; ViewGroup _root; public void CreateImageView() { _root = (ViewGroup)findViewById(R.id.root); _view = new ImageView[5]; for ( int i = 0; i< 5;i++) { _view[i] = new RadioButton(this); _view[i].setTag(i); RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(100, 100); layoutParams.leftMargin = 150; layoutParams.topMargin = 50; _view.setLayoutParams(layoutParams); _root.addView(_view[i]); } }
Click Event #
_view[j].setOnClickListener(new OnClickListener() { @Override public void onClick(View v) {
source share