如何在Android中处理触摸或按下事件? [英] How to handle touch or press down events in Android?
本文介绍了如何在Android中处理触摸或按下事件?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
好吧,所以我有4张图片浏览..
Alright so i have 4 image views..
我如何控制按下它们时发生的事情
How can i control what happens when they are pressed down and up
所以说如下:
其中一个图像是按下textview变为1,但当他们放弃那个时,文本将变回到0?
one of the images is press down a textview gets changed to 1 but when they let go of that one the text will change back to 0?
推荐答案
你需要使用 OnTouchListener 并让它在视图上监听
。 TouchEvents
You need to use an OnTouchListener and have it listen for TouchEvents
on your Views
.
例如:
MyTouchListener l = new MyTouchListener();
view.setOnTouchListener(l);
以下是 MyTouchListener
可能的示例看起来像:
Here is an example of what MyTouchListener
could look like:
class MyOnTouchListener implements OnTouchListener {
public boolean onTouch(View v, MotionEvent event) {
switch(event.getAction()) {
case MotionEvent.ACTION_DOWN:
// touch down code
break;
case MotionEvent.ACTION_MOVE:
// touch move code
break;
case MotionEvent.ACTION_UP:
// touch up code
break;
}
return true;
}
}
这篇关于如何在Android中处理触摸或按下事件?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文