我创建了一个ImageView
ImageView _view;
ViewGroup _root;
public void CreateImageView() {
_root = (ViewGroup) findViewById(R.id.root);
for (int i = 0; i < 5; i++) {
_view = new ImageView(this);
RelativeLayout.LayoutParams layoutParams = new RelativeLayout.LayoutParams(100, 100);
layoutParams.leftMargin = 150;
layoutParams.topMargin = 50;
_view.setLayoutParams(layoutParams);
_view.setId(i);
_root.addView(_view);
}
}
当我单击 id = 3 的图像视图时,应该调用一个 Toast。我怎样才能做到这一点?