本文介绍了如何在Android中设置的ImageView的onClicklistener方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我加入的S 的ImageView
的数组,并设置图像的每个的ImageView
动态,我受够了用它。但问题是,如何设置/上定义onClicklistener方法的的ImageView
?
下面是我的code:
的ImageView [] mImages;
INT []的图像= {R.drawable.sandle_icon1,R.drawable.sandle_icon2,
R.drawable.sandle_icon3,R.drawable.sandle_icon4};
的LinearLayout LL =新的LinearLayout(本);
mScrollViewImage.removeAllViews();
ll.setOrientation(LinearLayout.VERTICAL);
mImages =新的ImageView [images.length]
mScrollViewImage.addView(Ⅱ);
为(FLOOP = 0; FLOOP&所述; sandleicon.length; FLOOP ++){
mImages [FLOOP] =新ImageView的(这一点);
mImages [FLOOP] .setImageResource(图像[FLOOP]);
ll.addView(mImages [FLOOP]);
}
任何帮助将大大AP preciated。
解决方案
的(FLOOP = 0; FLOOP< sandleicon.length; FLOOP ++){
mImages [FLOOP] =新ImageView的(这一点);
mImages [FLOOP] .setImageResource(图像[FLOOP]);
mImages [FLOOP] .setId(FLOOP);
ll.addView(mImages [FLOOP]);
mImages [FLOOP] .setOnClickListener(新View.OnClickListener(){
公共无效的onClick(视图v){
//v.getId()会给你的形象标识
}
});
}
I am Adding an array of ImageView
s and set an image to each ImageView
dynamically and I'm done with it. But the problem is how to set/define onClicklistener Method on an ImageView
?
Here is my Code:
ImageView[] mImages;
int[] images={R.drawable.sandle_icon1, R.drawable.sandle_icon2,
R.drawable.sandle_icon3, R.drawable.sandle_icon4};
LinearLayout ll = new LinearLayout(this);
mScrollViewImage.removeAllViews();
ll.setOrientation(LinearLayout.VERTICAL);
mImages = new ImageView[images.length];
mScrollViewImage.addView(ll);
for (floop = 0; floop < sandleicon.length; floop++) {
mImages[floop] = new ImageView(this);
mImages[floop].setImageResource(images[floop]);
ll.addView(mImages[floop]);
}
Any helps will be greatly appreciated.
解决方案
for (floop = 0; floop < sandleicon.length; floop++) {
mImages[floop] = new ImageView(this);
mImages[floop].setImageResource(images[floop]);
mImages[floop].setId(floop);
ll.addView(mImages[floop]);
mImages[floop].setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
//v.getId() will give you the image id
}
});
}
这篇关于如何在Android中设置的ImageView的onClicklistener方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!