0

I want to display the button on user's right to left swipe on listitem, i have written below code in the adapter and it is working fine except it is also working on vertical swipe.How can i stop vertical swipe event?

final Button btnLoyaltyName = (Button) view .findViewById(R.id.loyaltynamebutton);

        btnLoyaltyName.setOnTouchListener(new View.OnTouchListener() {

            @Override
            public boolean onTouch(View v, MotionEvent event) {

                int action = event.getAction();

                switch (action) {
                case MotionEvent.ACTION_DOWN: {
                    downX = event.getX();
                    downY = event.getY();
                    return true;
                }
                case MotionEvent.ACTION_CANCEL: {
                    upX = event.getX();
                    upY = event.getY();

                    float deltaX = downX - upX;
                    float deltaY = downY - upY;

                    Log.i("afasf", "X Position==" + deltaX + "Y poastion="
                            + deltaY);

                    // if (deltaX > 0)
                    {
                        // swipe horizontal?
                        if (Math.abs(deltaX) > MIN_DISTANCE) {
                            // left or right

                            if (deltaX < 0) {
                                onSwipe(v);
                                return true;
                            }
                            if (deltaX > 0) {
                                onSwipe(v);
                                return true;
                            }
                        } else {
                            // Log.i(logTag, "Swipe was only " +
                            // Math.abs(deltaX) + " long, need at least " +
                            // MIN_DISTANCE);
                            return false; // We don't consume the event
                        }

                    }
                }
                }
                return false;

            }
        });
user853341
  • 149
  • 2
  • 12

1 Answers1

0

you are on the wrong path, read about GestureDetector, http://developer.android.com/reference/android/view/GestureDetector.html

pskink
  • 23,874
  • 6
  • 66
  • 77
  • Thanks for your reply, but i tried using GestureDetector but its onfling method does not call so i tried using above approach.I tried exactly same as mentioned in this link http://stackoverflow.com/questions/16017988/android-list-view-right-left-swipes-like-call-logs using OnSwipeTouchListener.java but onFilg's method is not getting called. – user853341 Sep 29 '13 at 07:14
  • this is because you feed your GestureDetector from wrong place, in case of a ListView it should be the ViewGroup that is used as the ListView item – pskink Sep 29 '13 at 08:45
  • Thanks again for the reply,my listiem has button and above two textview. if i swipe the button from right to left, button label will be changed.i am doing all this in cursoradapter's bindview method. is it wrong? – user853341 Sep 29 '13 at 10:50