1

hey guys Im trying to make a fadeout animation in my to do list app in android. I have this code

public void removeToDo(){
myItems.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
    @Override
    public boolean onItemLongClick(AdapterView<?> parent,  View view, final int position, long id) {



        ObjectAnimator anim = ObjectAnimator.ofFloat(view, View.ALPHA, 0);

        anim.addListener(new AnimatorListenerAdapter() {
            @Override
            public void onAnimationEnd(Animator animation) {
                items.remove(position);
                itemsAdapter.notifyDataSetChanged();
            }
        });

        anim.start();

        return true;
    }
});

}

yeah its fading out beautifully but the problem is when I added a new Item it reuses the row that fades out the item already so the result is that I will have a new row upon adding a new Item but without text on it.

https://i.sstatic.net/o6wPz.jpg

please help Im just a newbie :)

1 Answer 1

2

Try this solution. ObjectAnimator not reliable, Use Animation instead of this.

listView.setOnItemLongClickListener(new AdapterView.OnItemLongClickListener() {
            @Override
            public boolean onItemLongClick(AdapterView<?> parent, final View view, final int position, long id) {
                final Adapter adapter = (Adapter) parent.getAdapter();

                Animation fadeOut = new AlphaAnimation(1, 0);
                fadeOut.setInterpolator(new AccelerateInterpolator());
                fadeOut.setDuration(500);
                fadeOut.setAnimationListener(new Animation.AnimationListener() {
                    @Override
                    public void onAnimationStart(Animation animation) {

                    }

                    @Override
                    public void onAnimationEnd(Animation animation) {
                        adapter.pointItems.remove(position);
                        adapter.notifyDataSetChanged();
                    }

                    @Override
                    public void onAnimationRepeat(Animation animation) {

                    }
                });

                view.startAnimation(fadeOut);

                return true;
            }
        });
Sign up to request clarification or add additional context in comments.

2 Comments

thanks man it works. I also some comments that I can do it in RecyclerView and use ObjectAnimator?
I`am used only animation and recommend it to you.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.