Simple swipe gesture to activity tutorial? [closed]
Asked Answered
M

2

13

im looking for a turoial with source code on swipe gesutes, I dont want a view pager, I want a swipe gesture tutorial. here is one example I found but doesnt work for me

http://www.eridem.net/android-tip-010-left-and-right-swipe-gesture-events

I would like something like this, thanks Please no view pagers

Marceau answered 6/8, 2012 at 18:2 Comment(2)
What are you trying to swipe? Tell us the context. Are you swiping on a list? Within the cells of a list or just swiping across a view?Minuet
lets say i have and activty with an xml, when my user is in the activity/xml he swipes right and goes to a new activtyMarceau
M
11
    SimpleOnGestureListener mySimpleGestureListener = new SimpleOnGestureListener()
 {

    @Override
    public boolean onDoubleTap(MotionEvent e) { 
        Logout.debug("onDoubleTap");
        return super.onDoubleTap(e);
    }

    @Override
    public boolean onFling(MotionEvent e1, MotionEvent e2, float velocityX,float velocityY) 
    {
        String velocity="onFling: \n" + e1.toString() + "\n" + e2.toString() +"\n"
                + "velocityX= " + String.valueOf(velocityX) + "\n"
                + "velocityY= " + String.valueOf(velocityY) + "\n";
        Logout.debug("onFling velocity="+velocity);
                    return super.onFling(e1, e2, velocityX, velocityY);
    }

    @Override
    public void onLongPress(MotionEvent e) {
        Logout.debug("onLongPress: \n" + e.toString());
        super.onLongPress(e);
    }

    @Override
    public boolean onSingleTapConfirmed(MotionEvent e) {
        Logout.debug("onSingleTapConfirmed: \n" + e.toString());
        return super.onSingleTapConfirmed(e);
    }

    private boolean permissibleYVelocity(float velocityY)
    {
        if ((velocityY < -200) || (velocityY > 200))
        {
            return false;
        }
        else
        {
            return true;
        }

    }
};

GestureDetector myGestureDetector = new GestureDetector(mSimpleOnGestureListener);

View.OnTouchListener mOnListTouchListener = new  OnTouchListener()
{
    @Override
    public boolean onTouch(View view, MotionEvent event)
    {
        Logout.debug("list onTouch()");
         return myGestureDetector.onTouchEvent(event);
    }
};
Minuet answered 6/8, 2012 at 18:11 Comment(2)
does this have swipe, i mainly see onTouch listners and longlicksMarceau
So the slide gesture is really a Fling. So if velocityX is greater than say 200 or 300 its a swipe right, provided there is not also too much YVelocity (Scrolling). So I have the yVelocityCheck. This is all you need.Minuet
D
3

I would start by googling something like "Android basic swipe gesture". That was kinda what I did, and I ended up with this populare post on the subject: Fling gesture detection on grid layout

First hit on google was this: http://pcfandroid.wordpress.com/2011/07/17/swipe-with-android-android-tutorial/, also applicable for you're question

Dissociation answered 6/8, 2012 at 18:8 Comment(1)
Anything more organized or with source code, i taught myself by reading the codeMarceau

© 2022 - 2024 — McMap. All rights reserved.