Android

RecyclerView SwipeToDelete

그란. 2019. 4. 19. 16:54

 

gradle

implementation 'com.chauthai.swipereveallayout:swipe-reveal-layout:1.4.1'

 

xml

<com.chauthai.swipereveallayout.SwipeRevealLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:app="http://schemas.android.com/apk/res-auto"
    android:id="@+id/swipe_layout"
    app:dragEdge="right"
    app:mode="same_level"
    android:layout_width="match_parent"
    android:layout_height="wrap_content"
    android:background="@color/app_white">

    <LinearLayout
        android:id="@+id/bottom_wrapper"
        android:layout_width="100dp"
        android:layout_height="fill_parent"
        android:layout_gravity="center"
        android:background="#f00"
        android:gravity="center"
        android:orientation="horizontal">

        <ImageView
            android:layout_width="30dp"
            android:layout_height="30dp"
            android:src="@drawable/baseline_delete_forever_black_18dp"
            android:tint="@color/app_white" />

    </LinearLayout>

    <LinearLayout
        android:id="@+id/view_foreground"
        android:layout_width="match_parent"
        android:layout_height="wrap_content"
        android:background="@color/app_white"
        android:orientation="horizontal"
        android:paddingLeft="20dp"
        android:paddingTop="8dp"
        android:paddingBottom="8dp"
        android:weightSum="10">

        <TextView
            android:id="@+id/g_code"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.8"
            android:ellipsize="end"
            android:gravity="left|center_vertical"
            android:textColor="@color/app_black"
            android:textSize="@dimen/list_small_font" />

        <TextView
            android:id="@+id/g_name"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_toRightOf="@id/g_code"
            android:layout_weight="2.5"
            android:gravity="center"
            android:textColor="@color/app_black"
            android:textSize="10sp" />

        <TextView
            android:id="@+id/d_price"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_centerVertical="true"
            android:layout_marginLeft="5dp"
            android:layout_marginRight="30dp"
            android:layout_toRightOf="@id/g_name"
            android:layout_weight="1.5"
            android:ellipsize="end"
            android:gravity="center"
            android:paddingLeft="30dp"
            android:textColor="@color/app_black"
            android:textSize="@dimen/list_small_font" />

        <Spinner
            android:id="@+id/amount"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_marginRight="20dp"
            android:layout_weight="1"
            android:background="@drawable/spinner_small_list_bg"
            android:gravity="center"
            android:textSize="10sp" />

        <Spinner
            android:id="@+id/dc_rate"
            android:layout_width="0dp"
            android:layout_height="wrap_content"
            android:layout_weight="1.5"
            android:background="@drawable/spinner_small_list_bg"
            android:gravity="center"
            android:textSize="10sp" />

        <TextView
            android:id="@+id/tot_price"
            android:layout_width="0dp"
            android:layout_height="match_parent"
            android:layout_weight="1.4"
            android:ellipsize="end"
            android:gravity="right|center_vertical"
            android:textColor="@color/app_black"
            android:textSize="@dimen/list_small_font" />
    </LinearLayout>

</com.chauthai.swipereveallayout.SwipeRevealLayout>

 

 

 

            swipe_layout.setDragEdge(SwipeRevealLayout.DRAG_EDGE_RIGHT);
            swipe_layout.setSwipeListener(new SwipeRevealLayout.SwipeListener() {
                @Override
                public void onClosed(SwipeRevealLayout view) {
                }

                @Override
                public void onOpened(SwipeRevealLayout view) {
                }

                @Override
                public void onSlide(SwipeRevealLayout view, float slideOffset) {
                }
            });

            //스와이프 후 삭제 버튼
            bottom_wrapper.setOnClickListener(view1 -> {
                swipe_layout.postDelayed(() -> swipe_layout.close(true), 50);

                try {
                    onProductListener.onDeleteListener(getAdapterPosition());

                } catch (ClassCastException exception) {
                    Log.e("g", exception.getMessage());
                }
            });

 

'Android' 카테고리의 다른 글

showToast : Toast Custom  (0) 2019.04.19
도로명 주소 입력 받기 ( WebView + JS 연결)  (0) 2019.04.19
ScrollView PullToRefreshLayout  (0) 2019.04.19
Retrofit 통신  (0) 2019.04.19
RecyclerView 하단 합계 ( FooterView)  (0) 2019.04.19