Here is a simple Swipe detection template that detects up,down,left and right gestures. Hope someone may find it helpful to get started.
package com.code2care.swipedetectordemo;
import gesture.SwipeDetector;
import android.app.Activity;
import android.os.Bundle;
import android.view.Menu;
import android.view.MotionEvent;
import android.widget.TextView;
public class SwipeDemo extends Activity {
private TextView textview;
private SwipeDetector sd;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_swipe_demo);
textview = (TextView) findViewById(R.id.textView1);
sd = new SwipeDetector(this, new SwipeDetector.OnSwipeListener() {
@Override
public void onSwipeLeft(float distance, float velocity) {
textview.setText("Swipe Left Detected!");
}
@Override
public void onSwipeRight(float distance, float velocity) {
textview.setText("Swipe Right Detected!");
}
@Override
public void onSwipeDown(float distance, float velocity) {
textview.setText("Swipe Down Detected!");
}
@Override
public void onSwipeUp(float distance, float velocity) {
textview.setText("Swipe Up Detected!");
}
});
}
@Override
public boolean onCreateOptionsMenu(Menu menu) {
// Inflate the menu; this adds items to the action bar if it is present.
getMenuInflater().inflate(R.menu.swipe_demo, menu);
return true;
}
@Override
public boolean onTouchEvent(MotionEvent me) {
return sd.onTouch(null, me);
}
@Override
public boolean dispatchTouchEvent(MotionEvent ev) {
super.dispatchTouchEvent(ev);
return sd.onTouchEvent(ev);
}
}
✋️ Follow the complete code here: https://github.com/code2care/SwipeDetectorDemo
More Posts related to Android,
- Check Internet Connection WIFI 4G is active on Android Programmatically
- Android Emulator cannot be opened because the developer cannot be verified. [M1 Mac]
- How to Change Android Toast Position?
- Fail to connect to camera service Android java RuntimeException
- How to create Custom RatingBar Android Programming Tutorial
- Fixing Android unknown error 961 while downloading app
- Android AlertDialog with Yes No and Cancel Button
- Share or Send SMS via Android Intent
- The Android Virtual Device myEmulator is currently running an emulator and cannot be deleted.
- Pass data between two Android Activities and access it using Intent
- SQLite with Android Easy to Understand Tutorial that covers Select, Insert, Update and Delete
- [FIX] AndroidRuntime: FATAL EXCEPTION: main - java.lang.RuntimeException NullPointerException
- Android EditText Cursor Colour appears to be white
- Android Development - How to switch between two Activities
- Android xml error Attribute is missing the Android namespace prefix [Solution]
- Android : Remove ListView Separator/divider programmatically or using xml property
- Android is starting optimizing... app 1 of 1
- java.lang.NoClassDefFoundError android.support.v4.content.LocalBroadcastManager
- AlertDialog with single button example : Android
- Android : Exception raised during rendering: action_bar API 22
- Maven : java.lang.ClassNotFoundException: Xmx512m
- Android Lint app_name is not translated in af (Afrikaans) am (Amharic) ar (Arabic) bg (Bulgarian)
- Center align text in TextView Android Programming
- How to Download and Install Android adb Tool on Linux, Mac or Windows
- Multiline EditText in Android Example
More Posts:
- How to find version of Cargo in Rust - Rust
- Examples: Convert String to int in JavaScript - JavaScript
- How to remove quotes from a String in Python - Python
- Display full website URL/address in Safari macOS Browser - MacOS
- SharePoint workflow Canceled - Coercion Failed: Unable to transform the input lookup data into the requested type - SharePoint
- What does apt-get update command does? - Linux
- Python Comments Multiple Lines - Python
- How to Send or Publish SNS Message using AWS CLI - AWS