[英]How to handle touch or press down events in Android?
好吧,所以我有4个图像视图..
我怎样才能控制按下它们时发生的事情
所以说:
其中一个图像是按下textview变为1,但是当他们放弃那个时,文本会变回0?
您需要使用OnTouchListener并TouchEvents
在您的Views
上侦听TouchEvents
。
例如:
MyTouchListener l = new MyTouchListener();
view.setOnTouchListener(l);
以下是MyTouchListener
的示例:
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;
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.