package com.httptesting.boston_two; import android.app.Activity; import android.support.v7.app.AppCompatActivity; import android.os.Bundle; import android.view.MotionEvent; import android.view.GestureDetector; import android.support.v4.view.GestureDetectorCompat; import android.widget.TextView; public class MainActivity extends Activity implements GestureDetector.OnGestureListener,GestureDetector.OnDoubleTapListener{ private TextView tv; private GestureDetectorCompat gestureDetector; @Override protected void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); tv=(TextView)findViewById(R.id.textViraj); this.gestureDetector=new GestureDetectorCompat(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) { tv.setText("onSingleTapConfirmed"); return true; } @Override public boolean onDoubleTap(MotionEvent e) { tv.setText("onDoubleTap"); return true; } @Override public boolean onDoubleTapEvent(MotionEvent e) { tv.setText("onDoubleTapEvent"); return true; } @Override public boolean onDown(MotionEvent e) { tv.setText("onDown"); return true; } @Override public void onShowPress(MotionEvent e) { tv.setText("onShowPress"); } @Override public boolean onSingleTapUp(MotionEvent e) { tv.setText("onSingleTapUp"); return true; } @Override public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) { tv.setText("onScroll"); return true; } @Override public void onLongPress(MotionEvent e) { tv.setText("onLongPress"); } @Override public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) { tv.setText("onFling"); return true; } }
-=======================================================================
<?xml version="1.0" encoding="utf-8"?><RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android" xmlns:tools="http://schemas.android.com/tools" android:layout_width="match_parent" android:layout_height="match_parent" android:paddingBottom="@dimen/activity_vertical_margin" android:paddingLeft="@dimen/activity_horizontal_margin" android:paddingRight="@dimen/activity_horizontal_margin" android:paddingTop="@dimen/activity_vertical_margin" tools:context="com.httptesting.boston_two.MainActivity"> <TextView android:layout_width="wrap_content" android:layout_height="wrap_content" android:textAppearance="?android:attr/textAppearanceLarge" android:text="@string/msg" android:id="@+id/textViraj" android:layout_centerVertical="true" android:layout_centerHorizontal="true" /> </RelativeLayout>