Resource for Android Slight Left/Right Slide action on listview
Asked Answered
T

4

8

I am not sure if this question has been asked here or not. I look for a way to simulate the slide action in listview of Android. Similar to that of Samsung Galaxy/Nexus contact list actions.

As you can see from the below image I am sliding to the right and a different view is shown in place of the contact. (no number view)

enter image description here

Tuque answered 5/9, 2011 at 13:32 Comment(0)
I
2

Here's a nice post that may help you. Implementation may be a bit tricky, but that's a nice method of solving your problem IMHO. Hope this helps.

Indulgence answered 5/9, 2011 at 13:36 Comment(1)
That is good and I did read it but as you can see from my above screenshot. I am looking to achieve the greeny bit in the middle not move the entire view. Kind of indicative of the action being performed.Tuque
C
2

this link is very clear and useful

image of this source code

IOS 7 Swipe Gesture in Android listview. This repo provides listview swipe gesture pattern like IOS7 mailbox. messages to your Application.

Cockpit answered 28/3, 2015 at 15:46 Comment(0)
P
1

This is how I realize this action. We have a ListView lvSimple and we add onTouchListener to our lvSimple. This is my working code.

float historicX = Float.NaN, historicY = Float.NaN;
static final int DELTA = 50;
enum Direction {LEFT, RIGHT;}
...
ListView lvSimple = (ListView) findViewById(R.id.linLayout);
...
lvSimple.setOnTouchListener(new OnTouchListener() {
    @Override
    public boolean onTouch(View v, MotionEvent event) 
    {
        // TODO Auto-generated method stub
        switch (event.getAction()) 
        {
            case MotionEvent.ACTION_DOWN:
            historicX = event.getX();
            historicY = event.getY();
            break;

            case MotionEvent.ACTION_UP:
            if (event.getX() - historicX < -DELTA) 
            {
                FunctionDeleteRowWhenSlidingLeft();
                return true;
            }
            else if (event.getX() - historicX > DELTA)  
            {
                FunctionDeleteRowWhenSlidingRight();
                return true;
            } break;
            default: return false;
        }
        return false;
    }
});

where function FunctionDeleteRowWhenSlidingLeft() is calling when when we sliding to the left, FunctionDeleteRowWhenSlidingRight - to the right respectively. In this function you need paste code for animation.

Postulant answered 10/4, 2013 at 0:24 Comment(0)
L
1

If you want to Perform an action On Swiping:

Check out SwipeActionAdapter

It's an awesome library that allows Swipe in both directions with an underlying Layout or Color, and performs a desired action when the swipe/slide gesture is done. You can configure it to reveal/change the layout.

Left Swipe Right Swipe


If you want to swipe to Reveal actionable buttons:

Check out SwipeMenuListView

In a sense, it is more like the Swipe-able TableViews in iOS.

SwipeMenuListView SwipeMenuListView SwipeMenuListView

Looper answered 1/2, 2015 at 21:1 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.