catch double click on textview android

后端 未结 4 973
孤独总比滥情好
孤独总比滥情好 2021-01-21 03:33

i want to catch double click on textview for that i have used below code

but it still not working :(

TextView txtOne;

@Override
protected void onCreate(         


        
4条回答
  •  离开以前
    2021-01-21 03:43

    Try following steps.

    Step 1

    Write following code in your activity.

    // initialize the Gesture Detector
    gd = new GestureDetector(this,new OnGestureListener() {
        @Override
        public boolean onSingleTapUp(MotionEvent e) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public void onShowPress(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 onLongPress(MotionEvent e) {
            // TODO Auto-generated method stub
    
        }
    
        @Override
        public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,
                float velocityY) {
            // TODO Auto-generated method stub
            return false;
        }
    
        @Override
        public boolean onDown(MotionEvent e) {
            // TODO Auto-generated method stub
            return false;
        }
    });
    
    // set the on Double tap listener
    gd.setOnDoubleTapListener(new OnDoubleTapListener() {
        @Override
        public boolean onDoubleTap(MotionEvent e) {
            Toast.makeText(SplashActivity.this,"Double Tap",Toast.LENGTH_LONG).show();
        return false;
        }
    
        @Override
        public boolean onDoubleTapEvent(MotionEvent e) {
            // if the second tap hadn't been released and it's being moved
    
            return false;
        }
    
        @Override
        public boolean onSingleTapConfirmed(MotionEvent e) {
            // TODO Auto-generated method stub
            return false;
        }
    
    });
    

    Step 2

    Write following code for activity. Here gd will be GestureDetector object.

    txt.setOnTouchListener(new View.OnTouchListener() {
    
            @Override
            public boolean onTouch(View v, MotionEvent event) {
                // TODO Auto-generated method stub
                gd.onTouchEvent(event);
                return false;
            }
        });
    

提交回复
热议问题