0

I've need to recognize gestures over xml like this:

<?xml version="1.0" encoding="utf-8"?>
<TableLayout xmlns:android="http://schemas.android.com/apk/res/android"
             android:layout_width="wrap_content"
             android:layout_height="wrap_content"
             android:id="@+id/main_1"
             android:gravity="center"> 
</TableLayout>

In my activity add some rows into table:

private void buildField() {
    Square[][] field = game.getField();
    for (int i = 0, lenI = field.length; i < lenI; i++ ) {
        TableRow row = new TableRow(this); 
        for (int j = 0, lenJ = field[i].length; j < lenJ; j++) {
            Button button = new Button(this);
            buttons[i][j] = button;
            button.setOnClickListener(new Listener(i, j)); 
            row.addView(button, new TableRow.LayoutParams(TableRow.LayoutParams.WRAP_CONTENT,
                    TableRow.LayoutParams.WRAP_CONTENT));
            button.setWidth(107);
            button.setHeight(107);
        }
        layout.addView(row, new TableLayout.LayoutParams(TableLayout.LayoutParams.WRAP_CONTENT,
                TableLayout.LayoutParams.WRAP_CONTENT)); 
    }
}

how to fire setOnClickListener on button when user draw gesture over that row?

Mag
  • 1

1 Answers1

0

GestureOverlayView handle this automatically. See here for a tutorial to help you get started.

AggelosK
  • 4,313
  • 2
  • 32
  • 37
  • Thank i'm already seen this tutorial. But have some problem with how to send ontouch or click event to the row over which gesture was recognize. – Mag Jul 25 '12 at 17:27
  • @Mag If you want to fire the `OnClickListener` of a button when a certain gesture was performed by the user, you can just add the code of your button's `OnClickListener` inside the `onGesturePerformed` instead of firing the `OnClickListener` of that button. – AggelosK Jul 25 '12 at 17:32
  • @Mag You need to add just one `GestureOverlayView` that will be fullscreen. Then when a certain gesture is performed that matches a certain button action, do what that button is supposed to do in `OnGesturePerformed`.Otherwise, if you really want to use multiple `GestureOverlayViews` you can dynamically set an id to them by the `setId(int id)` method. – AggelosK Jul 25 '12 at 17:41
  • I need to know on which of the buttons was painted gesture, because I have only two gesture for all the buttons – Mag Jul 25 '12 at 17:55
  • @Mag Then the aproach that you said earlier, to use multiple `GestureOverlayViews`, maybe really the most suitable. If you make them the same size and in the same position as your buttons and give them custom ids using the way i previously mentioned, i think you will be alright. – AggelosK Jul 25 '12 at 18:03
  • I can not add gestureOverlayView inside the tablerow. `row.addView(gestureOverlayView, new GestureOverlayView.LayoutParams(GestureOverlayView.LayoutParams.FILL_PARENT, GestureOverlayView.LayoutParams.FILL_PARENT));` doesnt work – Mag Jul 30 '12 at 19:24
  • No errors. Just gestureoverlayview doesnt appears in the row. Manualy in the layout file all works great. – Mag Aug 02 '12 at 15:35