Welcome to collectivesolver - Programming & Software Q&A. A website you can trust. All programs tested and works. Contact: aviboots(AT)netvision.net.il
Liquid Web Managed Dedicated Server: RAID 1 SSD with 16GB of RAM minimum! 24/7 On-Site Heroic Support! Industry-Leading SLA!

BlueHost Web Hosting

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

Ecommerce Software - Best Ecommerce Platform Made for You - Free Trial

getflywheel wordpress hosting


Liquid Web Cloud VPS Hosting

8,365 questions

11,625 answers

573 users

How to use GestureDetector and MotionEvent in Android Java

1 Answer

0 votes
package com.example.avi.myapplication;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.widget.TextView;
import android.view.MotionEvent;
import android.view.GestureDetector;

public class MainActivity extends AppCompatActivity implements
                                                     GestureDetector.OnGestureListener,
                                                     GestureDetector.OnDoubleTapListener{

    private TextView myText;
    private GestureDetector gestureDetector;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);

        myText = (TextView) findViewById(R.id.myText);

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

    @Override
    public boolean onTouchEvent(MotionEvent event) {
        this.gestureDetector.onTouchEvent(event);
        return super.onTouchEvent(event);
    }

    @Override
    public boolean onSingleTapConfirmed (MotionEvent e){
        myText.setText("onSingleTapConfirmed");
        return false;
    }

    @Override
    public boolean onDoubleTap (MotionEvent e){
        myText.setText("onDoubleTap");
        return false;
    }

    @Override
    public boolean onDoubleTapEvent (MotionEvent e){
        myText.setText("onDoubleTapEvent");
        return false;
    }

    @Override
    public boolean onDown (MotionEvent e){
        myText.setText("onDown");
        return false;
    }

    @Override
    public void onShowPress (MotionEvent e){
        myText.setText("onShowPress");
    }

    @Override
    public boolean onSingleTapUp (MotionEvent e){
        myText.setText("onSingleTapUp");
        return false;
    }

    @Override
    public boolean onScroll (MotionEvent e1, MotionEvent e2,float distanceX, float distanceY){
        myText.setText("onScroll");
        return false;
    }

    @Override
    public void onLongPress (MotionEvent e){
        myText.setText("onLongPress");
    }

    @Override
    public boolean onFling (MotionEvent e1, MotionEvent e2,float velocityX, float velocityY){
        myText.setText("onFling");
        return false;
    }
}

 




answered Mar 29, 2017 by avibootz
...