Question

I'm trying to implement swipe to dismiss feature to my app, I have a TableLayout with a bunch of TableRows inside it, and each table row has a TextView and EditText, like this

<TableLayout
    android:id="@+id/tableLayout"
    android:layout_width="match_parent"
    android:layout_height="wrap_content">

    <TableRow
        android:id="@+id/tableRow"
        android:layout_width="match_parent"
        android:layout_height="wrap_content">

        <TextView
            android:id="@+id/textView"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:text="@string/textView"
            android:textAppearance="?android:attr/textAppearanceLarge"
            android:layout_weight="2"/>

        <EditText
            android:id="@+id/editText"
            android:layout_width="wrap_content"
            android:layout_height="wrap_content"
            android:ems="7"
            android:layout_weight="1"
            android:selectAllOnFocus="true"
            android:inputType="numberDecimal"/>
    </TableRow>
</TableLayout>

And following this I added the SwipeDismissTouchListener.java class to my app and added this to my Activity's code inside the onActivityCreated() method.

        tableRow.setOnTouchListener(new SwipeDismissTouchListener(
                      tableRow,
                      null,
                        new SwipeDismissTouchListener.DismissCallbacks() {
                            @Override
                            public boolean canDismiss(Object token) {
                                return true;
                            }

                            @Override
                            public void onDismiss(View view, Object token) {
                                tableLayout.removeView(tableRow);
                            }
                      }));

But nothing's happening when I swipe the tableRow, what seems to be the problem?

Was it helpful?

Solution

You will need to implement onClickListener for the view. Then only SwipeDismissTouchListener seems to work.

Refer this. Rest of your code looks fine.

Hope this helps.

OTHER TIPS

 tableRow.setOnTouchListener(new SwipeDismissTouchListener(
                      tableRow,
                      null,
                        new SwipeDismissTouchListener.DismissCallbacks() {
                            @Override
                            public boolean canDismiss(Object token) {
                                return true;
                            }

                            @Override
                            public void onDismiss(View view, Object token) {
                                tableLayout.removeView(view);
                            }
                      }));
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top