Signo Signo - 2 months ago 10
Java Question

Add animation to listView row deletion Android

I have a

listView
where every row has a visible delete button that onClick removes the selected row.. In order to delete the row I delete the correct item from my
ArrayList
and then call the
notifyDataSetChanged()
of the
Adapter
.
What I wanted to know if it's there a possibility to edit the row animation so when I delete a row it moves from left to right.

Can someone give me any hint?

Answer
Animation anim = AnimationUtils.loadAnimation(
                     GoTransitApp.this, android.R.anim.slide_out_right
                 );
anim.setDuration(500);
listView.getChildAt(index).startAnimation(anim );

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

    public void run() {

        FavouritesManager.getInstance().remove(
            FavouritesManager.getInstance().getTripManagerAtIndex(index)
        );
        populateList();
        adapter.notifyDataSetChanged();

    }

}, anim.getDuration());

You can use this for top-down animation :

<set xmlns:android="http://schemas.android.com/apk/res/android">
        <translate android:fromYDelta="20%p" android:toYDelta="-20"
            android:duration="@android:integer/config_mediumAnimTime"/>
        <alpha android:fromAlpha="0.0" android:toAlpha="1.0"
            android:duration="@android:integer/config_mediumAnimTime" />
</set>