我一生都无法在网上找到任何帮助来向我描述为什么“ACTION_DOWN”的延迟不起作用。只要我触摸图像,我的其余代码就会执行。我的意图是放在 //additional code 和 //end additional code comments 之间。需要放在别处吗?提前致谢!
编辑:我会使用 onLongClickListener 但我的意图是延长对象必须被持有的时间才能开始意图。
mImage = (ImageView)MainActivity.this.findViewById(R.id.Floaterimg);
mImage.setOnTouchListener(new View.OnTouchListener() {
final Handler handler2 = new Handler();
Runnable mLongPressed = new Runnable() {
public void run() {
Log.i("", "Long press!");
}
};
@Override
public boolean onTouch(View v, MotionEvent event){
if(event.getAction() == MotionEvent.ACTION_DOWN)
handler2.postDelayed(mLongPressed, 3000);
//additional code
//end of additional code
if((event.getAction() == MotionEvent.ACTION_MOVE)||
(event.getAction() == MotionEvent.ACTION_UP))
handler2.removeCallbacks(mLongPressed);
return false;
}
});