Android 安卓:如何更改每次触摸的图像

Android 安卓:如何更改每次触摸的图像,android,image,button,touch,uievent,Android,Image,Button,Touch,Uievent,我想在用户每次触摸屏幕时更改图像。我想让用户点击屏幕,图像每次都会改变,在第五次触摸时,它会返回到添加文本的原始图像 我看过 我尝试了IUevents和StateListdrawable。我不知道如何在每次触摸后(屏幕上的任何位置)实际更改图像。您需要创建自定义类,该类将ImageView扩展为现在显示整个屏幕的ImageView > First store the path/location of images into an array/list etc. > In custo

我想在用户每次触摸屏幕时更改图像。我想让用户点击屏幕,图像每次都会改变,在第五次触摸时,它会返回到添加文本的原始图像

我看过


我尝试了IUevents和StateListdrawable。我不知道如何在每次触摸后(屏幕上的任何位置)实际更改图像。

您需要创建自定义类,该类将ImageView扩展为现在显示整个屏幕的ImageView

> First store the path/location of images into an array/list etc.
> In custom class implement the onTouch event.
> create the counter object in this custom class.
> now in onTouch check in down event that check the counter value with array size if counter==array.length()-1 then set counter as 0 otherwise increment in counter object.
> now get the path of the image and set into the imageview as background

为什么不能使用普通的ImageView?这样做:

ArrayList<Integer> picList = new ArrayList<Integer>(); 
// populate the list with the int value of the pictures in drawable.
picList.add(R.drawable.apple);
picList.add(R.drawable.horse);
//etc
int touches = 0;
int loop = 0;
ImageView picture = (ImageView) findViewById(R.id.your_picture);
picture.setOnClickListener(new View.OnClickListener() {

        @Override
        public void onClick(View v) {
           if (touches < 4)
                v.setBackgroundDrawable(picList.get(touches));
                touches++;
           } else {
                touches = 0;
                loop = 1;
                v.setBackgroundDrawable(picList.get(touches));
           }
           if (loop = 1){
           // Create a TextView and set the text or make it in the xml with Visible="Gone" and make is visible here.
           }
    });
ArrayList picList=new ArrayList();
//使用drawable中图片的int值填充列表。
picList.add(R.drawable.apple);
picList.add(R.drawable.horse);
//等
int=0;
int循环=0;
ImageView图片=(ImageView)findViewById(R.id.your_图片);
picture.setOnClickListener(新视图.OnClickListener(){
@凌驾
公共void onClick(视图v){
如果(接触<4)
v、 挫折感(picList.get(touch));
触摸++;
}否则{
接触=0;
循环=1;
v、 挫折感(picList.get(touch));
}
如果(循环=1){
//创建一个TextView并设置文本,或者使用Visible=“Gone”将其放入xml中,并在此处显示make。
}
});

你能给我一些样品吗?=)您是否有更多的样本或已完成的样本来测试此功能?=)我刚为你做的?这不是样品。你不能让它工作吗?