【发布时间】:2011-11-11 15:44:28
【问题描述】:
我遇到的问题是我正在为 onTouch 事件使用触摸侦听器,当我只触摸一次时,似乎不止一次调用触摸。 以下是我的代码
final TextView tv = (TextView)findViewById(R.id.TextView01);
tv.setOnTouchListener(new View.OnTouchListener() {
int count1 =0;
int count2=0;
public boolean onTouch(View arg0, MotionEvent event) {
Log.d("Code777","Touch is being called finger");
int i = event.getPointerCount();
if(i==1 )
{
if(count1==0)
{
Log.d("Code777","Touched with 1 finger");
count1++;
count2=0;
}
}
if (i==2 )
{
if(count2==0)
{
Log.d("Code777","Touched with 2 fingers");
edit.append(tv.getText());
count2++;
count1=0;
}
}
return true;
}
});
我是不是做错了什么?? 单点触控和双点触控都会打印 3-4 次以上的日志
问题更新的问题是两个事件现在都被触发了
if(event.getAction() == MotionEvent.ACTION_POINTER_2_DOWN)
{
Log.d("Code777","2 finger touch");
return true;
}else if(event.getAction() == MotionEvent.ACTION_DOWN)
{
Log.d("Code777","Touched with 1 finger");
return true;
}
【问题讨论】:
标签: android touch-event ontouchlistener