0

在我的应用程序中,我需要双击图像视图,因为我实现了手势。在这里我也使用了图像视图,我无法识别哪个图像被点击了它的图像一个或图像。我在我的自定义适配器中实现了这段代码。这是我的代码供您参考,

gestureDetector = new GestureDetector(this);
        gestureDetector.setOnDoubleTapListener(this);

holder.imgOne.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return gestureDetector.onTouchEvent(event);
            }
        });
        holder.imgTwo.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                return gestureDetector.onTouchEvent(event);
            }
        });

        //////////////////////

            @Override
    public boolean onDoubleTap(MotionEvent arg0) {
        Log.e("DOUBLE TAP", "WORKING");
        return true;
    }

    @Override
    public boolean onDoubleTapEvent(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent arg0) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onDown(MotionEvent e) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
            float velocityY) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onLongPress(MotionEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX,
            float distanceY) {
        // TODO Auto-generated method stub
        return false;
    }

    @Override
    public void onShowPress(MotionEvent e) {
        // TODO Auto-generated method stub

    }

    @Override
    public boolean onSingleTapUp(MotionEvent e) {
        Log.e("SINGLE TAB CLICKED", e.getSource() + "");
        // new PopupImageDialog(assingValue.leftPicThumb, "leftPic").execute();
        return true;
    }

如果我们实施onClickListener()意味着我们可以获得 ID,那么我如何才能获得 ID。我如何识别按钮触摸。提前致谢。

4

1 回答 1

0

好吧,也许它是某种肮脏的黑客,但我希望它会奏效。

holder.imgOne.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                event.setSource(v.getId);
                return gestureDetector.onTouchEvent(event);
            }
        });
        holder.imgTwo.setOnTouchListener(new View.OnTouchListener() {
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                event.setSource(v.getId);
                return gestureDetector.onTouchEvent(event);
            }
        });

然后使用 getSource() 获取视图 ID。

于 2013-04-23T11:27:27.057 回答