Bhabani Shankar
Bhabani Shankar

Reputation: 1285

Finger swipe in Android application

I have created an application where in I have a page which contains for text and one 'Next' button and one 'Previous' button. Clicking 'Next' button, page shows some next text that is being takes from a list which contains a list of String text. 'Previous' button shows the last visited text.

It is working fine. But now I want to implement something new where swipe of finger by user would take to the next text or previous. Finger swipe as used while accepting a call.

Upvotes: 0

Views: 4662

Answers (3)

Andro Selva
Andro Selva

Reputation: 54322

You are looking for gesture detectors. And you can find it here.

http://android-journey.blogspot.com/2010/01/android-gestures.html

http://coderzheaven.com/2011/03/using-gestures-in-androida-simple-example/

    @Override
    public boolean onTouchEvent(MotionEvent me) {
        return gestureScanner.onTouchEvent(me);
    }


    public boolean onDown(MotionEvent e) {
        viewA.setText("-" + "DOWN" + "-");
        return true;
    }

    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY) {
        viewA.setText("-" + "FLING" + "-");
        return true;
    }


    public void onLongPress(MotionEvent e) {
        viewA.setText("-" + "LONG PRESS" + "-");
    }


    public boolean onScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY) {
        viewA.setText("-" + "SCROLL" + "-");
        return true;
    }


    public void onShowPress(MotionEvent e) {
        viewA.setText("-" + "SHOW PRESS" + "-");
    }


    public boolean onSingleTapUp(MotionEvent e) {
        viewA.setText("-" + "SINGLE TAP UP" + "-");
        return true;
    }

Upvotes: 2

Maggie
Maggie

Reputation: 8071

Have a look at the GreenDroid project. It has a simple swipe view that can be easily customized. In particular, have a look at PagedView and examples on how to use it.

Upvotes: 0

Ljdawson
Ljdawson

Reputation: 12229

Swipe to next view is the default behaviour for the Gallery class, you could start by giving this a try or extending it to meet your needs. Hope this helps!

Upvotes: 0

Related Questions