Skip to content
This repository has been archived by the owner on Nov 9, 2017. It is now read-only.

AnimateDismissAdapter

nhaarman edited this page Apr 9, 2013 · 1 revision

With the AnimateDismissAdapter you can select list item positions which you want to remove. The adapter takes care of animating the items out of view. After the animation is done, you need to remove the items from your BaseAdapter.

Usage

  • Implement your own BaseAdapter, or use an existing one.
  • Implement a OnDismissCallback for your AnimateDismissAdapter.
  • Create a new AnimateDismissAdapter, providing your BaseAdapter and OnDismissCallback.
  • Set your ListView to your AnimateDismissAdapter.
  • Set your AnimateDismissAdapter to your ListView.
  • Call animateDismiss(Collection<Integer>) on your AnimateDismissAdapter to animate dismissal.

Example

Setup

MyListAdapter mAdapter = new MyListAdapter(this, getItems());

OnDismissCallback myOnDismissCallback = new OnDismissCallback() {

    @Override
    public void onDismiss(ListView listView, int[] reverseSortedPositions){
        for (int position: reverseSortedPositions) {
            mAdapter.remove(position);
        }
    }
};

mAnimateDismissAdapter = new AnimateDismissAdapter(mAdapter, myOnDismissCallback);

mAnimateDismissAdapter.setListView(getListView());
getListView().setAdapter(mAnimateDismissAdapter);

Dismissing

public void dismissItems(Collection<Integer> positionsToDismiss){
    mAnimateDismissAdapter.animateDismiss(positionsToDismiss);
}
Clone this wiki locally