0

I'm able to perform swipes on list view. I want to show one color when swiped from L -> R and different color when swiped from R -> L. Can anyone please help me how to achieve this. Currently i use the code like below to identifying the gestures.

public class GestureListener : Java.Lang.Object, GestureDetector.IOnGestureListener
{
    public delegate void SwipeLeftEventHandler(MotionEvent first, MotionEvent second);
    public event SwipeLeftEventHandler SwipeLeftEvent;

    public delegate void SwipeRightEvetnHandler(MotionEvent first, MotionEvent second);
    public event SwipeRightEvetnHandler SwipeRightEvent;

    //public event Action LeftEvent;
    //public event Action RightEvent;
    private static int SWIPE_MAX_OFF_PATH = 300;
    private static int SWIPE_MIN_DISTANCE = 100;
    private static int SWIPE_THRESHOLD_VELOCITY = 10;

    public GestureListener()
    {
    }

    public bool OnFling(MotionEvent e1, MotionEvent e2, float velocityX, float velocityY)
    {
        try
        {
            if (Math.Abs(e1.GetY() - e2.GetY()) > SWIPE_MAX_OFF_PATH)
                return false;
            // right to left swipe
            if (e1.GetX() - e2.GetX() > SWIPE_MIN_DISTANCE && Math.Abs(velocityX) > SWIPE_THRESHOLD_VELOCITY && SwipeLeftEvent /*LeftEvent*/ != null)
                SwipeLeftEvent(e1, e2); //LeftEvent(); //Toast.MakeText(view.Context, "Left Swipe", ToastLength.Short).Show();
            else if (e2.GetX() - e1.GetX() > SWIPE_MIN_DISTANCE && Math.Abs(velocityX) > SWIPE_THRESHOLD_VELOCITY && SwipeRightEvent /*RightEvent*/ != null)
                SwipeRightEvent(e1, e2); //RightEvent(); // Toast.MakeText(view.Context, "Right Swipe", ToastLength.Short).Show();
        }
        catch (Exception e)
        {
            // nothing
        }
        return false;
    }

    public bool OnDown(MotionEvent e)
    {
        return true;
    }
    public void OnLongPress(MotionEvent e)
    {
    }
    public bool OnScroll(MotionEvent e1, MotionEvent e2, float distanceX, float distanceY)
    {
        return true;
    }
    public void OnShowPress(MotionEvent e)
    {
    }
    public bool OnSingleTapUp(MotionEvent e)
    {
        return true;
    }
}
Morteza Soleimani
  • 2,652
  • 3
  • 25
  • 44
Krishna
  • 347
  • 1
  • 6
  • 23
  • Show a color where? Are you changing the entire list color, just the list item? The code you posted doesn't appear to indicate any attempt at changing color for any elements so it's hard to go off with what you've currently posted... – CodyEngel Sep 08 '14 at 18:08
  • I want to change the color of the row in the listview on which swipe action occurs. the code i posted i got to the point where i can identify on which row swipe occured. – Krishna Sep 09 '14 at 12:25

1 Answers1

0

You should be able to change the background color through this.setBackgroundColor(YOURCOLORHERE), where this is the row detected. Here is a similar question, please let me know if this solved your problem.

Community
  • 1
  • 1
CodyEngel
  • 1,501
  • 14
  • 22