madhall
madhall

Reputation: 182

Kotlin Recycler View with Multiple View - alternative Swipe to ability

I am using RecyclerView.ViewHolder to display different layouts in a recyclerview to display the below layout. Also using a Adapter to achieve this. -But I would also like to add a Swipe to Delete on the CardView (Event) of the below image and not the view of the time between events. Is this possible and any suggested approaches please? enter image description here

Upvotes: 1

Views: 427

Answers (1)

Vatsal kesarwani
Vatsal kesarwani

Reputation: 692

This Item touch helper will help you to achieve the above.

ItemTouchHelper.SimpleCallback itemTouch=new ItemTouchHelper.SimpleCallback(0,ItemTouchHelper.LEFT | ItemTouchHelper.RIGHT) {
    @Override
    public boolean onMove(@NonNull RecyclerView recyclerView, @NonNull RecyclerView.ViewHolder viewHolder, @NonNull RecyclerView.ViewHolder target) {
        return false;
    }

    @Override
    public void onSwiped(@NonNull RecyclerView.ViewHolder viewHolder, int direction) {
        //delete item in list
        recyclerAdapter.notifyDataSetChanged();
    }
};

Upvotes: 1

Related Questions