如何在两个或多个不同的自定义视图上应用相同的双击触摸监听器?
view1.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return mGestureDetector.onTouchEvent(event);
}
});
view2.setOnTouchListener(new View.OnTouchListener() {
@Override
public boolean onTouch(View v, MotionEvent event) {
return mGestureDetector.onTouchEvent(event);
}
});
mGestureDetector = new GestureDetector(new GestureDetector.SimpleOnGestureListener() {
@Override
public void onLongPress(MotionEvent e)
{
displayPTZControlsPopup(corresponding view id);
}
@Override
public boolean onDoubleTap(MotionEvent e)
{
Intent intent = new Intent(VideoView.this,FullScreenVideo.class);
startActivity(intent);
return true;
}
@Override
public boolean onDown(MotionEvent e)
{
return true;
}
});
mGestureDetector.setIsLongpressEnabled(true);
谁能帮我?
最佳答案
这样做:
view1.setOnTouchListener(this);
view2.setOnTouchListener(this);
@Override
public boolean onTouch(final View view, MotionEvent event) {
if(view.getId() == idOfYourView1 || view.getId() == idOfYourView2) {
//Apply the method to one of the view touched
}
}
关于android - Android代码将相同的双击触摸监听器应用于两个或多个不同的自定义 View ,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/11888388/