Bonjour,

J'ai crée un table layout avec 3 table row comportant 3 boutons chacun.
Je voudrais en utilise le balayage (swip) pour intervertir le noms des boutons.

Mais je ne comprends pas comment utilisé le swip, la méthode onTouch ne m'affiche rien quand je tape sur la zone ou il y a le table layout.

Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
 
 
public class MainActivity extends AppCompatActivity implements GestureDetector.OnGestureListener, GestureDetector.OnDoubleTapListener {
 
    private static final String DEBUG_TAG = "Gestures";
    private GestureDetectorCompat mDetector;
 
    private static final int SWIPE_MIN_DISTANCE = 120;
    private static final int SWIPE_THRESHOLD_VELOCITY = 200;
 
 
 
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
 
 
        mDetector = new GestureDetectorCompat(this,this);
        mDetector.setOnDoubleTapListener(this);
 
    }
 
    @Override
    public boolean onTouchEvent(MotionEvent event) {
 
        final int X = (int) event.getRawX() ;
        final int Y = (int) event.getRawY() ;
 
 
        int action = MotionEventCompat.getActionMasked(event);
        switch(action)
        {
            case (MotionEvent.ACTION_DOWN):
 
                Log.d(DEBUG_TAG,"ACTION_DOWN : " + X + " ||| " +Y);
 
                return true;
 
            case MotionEvent.ACTION_MOVE:
                Log.d(DEBUG_TAG,"ACTION_MOVE : " + X + " ||| " +Y);
                return true;
 
            default:
                return super.onTouchEvent(event);
        }
 
        //mDetector.onTouchEvent(event);
        //return super.onTouchEvent(event);
    }
 
 
    @Override
    public boolean onFling(MotionEvent event1, MotionEvent event2, float velocityX, float velocityY) {
 
        if (event1.getX() - event2.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) // Left swipe
        {
            Log.d(DEBUG_TAG,"onFling : " + event1.getX() +"|||"+ event2.getX());
        }
        else if (event2.getX() - event1.getX() > SWIPE_MIN_DISTANCE && Math.abs(velocityX) > SWIPE_THRESHOLD_VELOCITY) // Right swipe...
        {
            Log.d(DEBUG_TAG,"onFling : " + event1.getX() +"|||"+ event2.getX());
        }
        else if (event1.getY() - event2.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) // Swipe up...
        {
            Log.d(DEBUG_TAG,"onFling : " + event1.getX() +"|||"+ event2.getX());
        }
        else if (event2.getY() - event1.getY() > SWIPE_MIN_DISTANCE && Math.abs(velocityY) > SWIPE_THRESHOLD_VELOCITY) // Swipe down...
        {
            Log.d(DEBUG_TAG,"onFling : " + event1.getX() +"|||"+ event2.getX());
        }
        return false;
 
    }
}
Code : Sélectionner tout - Visualiser dans une fenêtre à part
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
 
<?xml version="1.0" encoding="utf-8"?>
<RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:id="@+id/activity_main"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context="com.example.idriss.taquinv2.MainActivity">
 
    <TableLayout
        android:layout_width="match_parent"
        android:layout_alignParentLeft="true"
        android:layout_alignParentStart="true"
        tools:ignore="UselessLeaf,UselessParent"
        android:id="@+id/tab"
        android:stretchColumns="0,1,2"
        android:layout_alignParentTop="true"
        android:layout_height="wrap_content">
 
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/l1">
 
            <Button
                android:text="1"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/b1"
                tools:ignore="ButtonStyle,HardcodedText" />
 
            <Button
                android:text="2"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/b2"
                tools:ignore="ButtonStyle,HardcodedText" />
 
            <Button
                android:text="3"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/b3"
                tools:ignore="ButtonStyle,HardcodedText" />
 
        </TableRow>
 
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/l2">
 
            <Button
                android:text="4"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/b4"
                tools:ignore="ButtonStyle,HardcodedText" />
 
            <Button
                android:text="5"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/b5"
                tools:ignore="ButtonStyle,HardcodedText" />
 
            <Button
                android:text="6"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/b6"
                tools:ignore="ButtonStyle,HardcodedText" />
        </TableRow>
 
        <TableRow
            android:layout_width="match_parent"
            android:layout_height="match_parent"
            android:id="@+id/l3" >
 
            <Button
                android:text="7"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/b7"
                tools:ignore="ButtonStyle,HardcodedText" />
 
            <Button
                android:text="8"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/b8"
                tools:ignore="ButtonStyle,HardcodedText" />
 
            <Button
                android:text="9"
                android:layout_width="wrap_content"
                android:layout_height="wrap_content"
                android:id="@+id/b9"
                tools:ignore="ButtonStyle,HardcodedText,UnusedAttribute"
                android:backgroundTint="@android:color/background_dark" />
        </TableRow>
 
    </TableLayout>
 
 
</RelativeLayout>