KD-21 KD-21 - 1 year ago 212
Android Question

Switch Screen/Activity By Swiping Android Java

I have an application with different screens/activity's. At the moment it works fine, but I've a previous and next button. I'll remove this button, and use a swipe move to "say" next of previous. I found a lot on the internet, Something about Action detection, But it doesn't work with my listview. When I swipe on a textview it works fine, but when I put the same code in my code with the listview, it doesn't detect anything anymore.

Can anybody help me?

In my own code I use a: ListAdapter, onItemClick and a public View getView to put some images and textviews in my listview.

The onTouchEvent what does not work with my listview.

public boolean onTouchEvent(MotionEvent touchevent) {
switch (touchevent.getAction()) {
// when user first touches the screen we get x and y coordinate
case MotionEvent.ACTION_DOWN: {
x1 = touchevent.getX();
y1 = touchevent.getY();
case MotionEvent.ACTION_UP: {
x2 = touchevent.getX();
y2 = touchevent.getY();

// if left to right sweep event on screen
if (x1 < x2) {
Toast.makeText(this, "Left to Right Swap Performed", Toast.LENGTH_LONG).show();

// if right to left sweep event on screen
if (x1 > x2) {
Toast.makeText(this, "Right to Left Swap Performed", Toast.LENGTH_LONG).show();

// if UP to Down sweep event on screen
if (y1 < y2) {
Toast.makeText(this, "UP to Down Swap Performed", Toast.LENGTH_LONG).show();

// if Down to UP sweep event on screen
if (y1 > y2) {
Toast.makeText(this, "Down to UP Swap Performed", Toast.LENGTH_LONG).show();
return false;


But everything I find is with different classes. In the examples, they use
. But I have only my
and these is running, and when I click my next button, it reloads the main activity, and shows other information And again and again. till my counter is on its max.

Answer Source
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download