Skip to content Skip to sidebar Skip to footer

Programmatically "swipe-to-dismiss" An Item In A Listview/recyclerview?

I need to be able to programmatically dismiss an item inside a RecyclerView without the user actually swiping (instead I want to dismiss the item when they tap a button in the card

Solution 1:

Use a ListView or RecyclerView with custom adapter, and call notifyDataSetChanged after removing an item from the datalist:

privatevoidremoveListItem(View rowView, final int position) {

    Animation anim = AnimationUtils.loadAnimation(this,
            android.R.anim.slide_out_right);
    anim.setDuration(500);
    rowView.startAnimation(anim);

    new Handler().postDelayed(new Runnable() {

        publicvoidrun() {

            values.remove(position); //Remove the current content from the array

            adapter.notifyDataSetChanged(); //Refresh list
        }

    }, anim.getDuration());
}

Solution 2:

Use one of the libraries that offer the swipe to dissmis funcionality ad extract the animation part, if im not mistaken its at the action_up at the onTouch(). Then call it from your onClick of the button.

Post a Comment for "Programmatically "swipe-to-dismiss" An Item In A Listview/recyclerview?"