0

I'm using the setOnTouchlistner class for detecting left and right swipes. I can get it to work fine on a listview, but the listview is too small to get a good swipe every time.

I then tried to set the swipe to the main LinearLayout. I have three other LinearLayout inside this. But it is not working thanks for any help.

<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:baselineAligned="false"
android:orientation="horizontal"
android:id="@+id/driveView"
android:focusableInTouchMode="true"
android:focusable="true"
android:clickable="true">

<LinearLayout
    android:layout_width="wrap_content"
    android:layout_height="match_parent"
    android:orientation="vertical" >

Here is the code:

private LinearLayout myView = null;
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.drive);
myView = (LinearLayout)findViewById(R.id.driveView);

myView.setOnTouchListener(new OnSwipeTouchListener(mContext) {
        @Override
        public void onSwipeLeft() {
            showdrivedialog(mContext, "Drive List", "Change to Ascending list!");
        }

        public void onSwipeRight() {
              showdrivedialog(mContext, "Drive List", "Change to Descending list!");
        }
    });
Neil Lunn
  • 148,042
  • 36
  • 346
  • 317
Kim HJ
  • 1,183
  • 2
  • 11
  • 37
  • If this view has child views with touch listener you need to return false on them so this view can get the touch – Xjasz Mar 19 '15 at 01:30
  • None of the other views have touch listener, I have onClickListner, onFocusChangeListner, onEditorActionListner and OnItemClickListner. Thanks. – Kim HJ Mar 19 '15 at 20:17

1 Answers1

0

Two matters I want to mention.

1) I don't know about OnSwipeTouchListener but I got interested. I suspect android:clickable="true" should be false because there seems to be a conflict between swiping and clicking.

2) Look at this SO link @ How to handle right to left swipe gestures. I don't know where you got the OnSwipeTouchListener class but you can copy the one with 274 votes!

Personally I did not use this class. I have used and extended HorizontalScrollView.

Community
  • 1
  • 1
The Original Android
  • 6,147
  • 3
  • 26
  • 31
  • I did try with clickable set to false, but on another post someone got it to work by setting it to true. That is the same OnSwipeTouchListener. – Kim HJ Mar 19 '15 at 20:08