문제

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();
            break;
        }
        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();
            }
            break;
        }
    }
    return false;
}

Update

But everything I find is with different classes. In the examples, they use fragment1.java, fragment2.java, fragment3.java. But I have only my main_activity.java 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.

도움이 되었습니까?

해결책

다른 팁

Use a ViewPager instead of manually doing all the touch-calculations. This will give you an overview over the ViewPager widget: http://developer.android.com/reference/android/support/v4/view/ViewPager.html

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top