ListView animation update adapter for animation

I have ListViewwith an adapter. When I click on an element on ListView, the adapter is cleared and filled with new content. I want to apply two animations: one when the adapter is cleared (elements are shifted to the left when removed from the adapter), and the other when new elements are added to the adapter (new elements are shifted to the right).

So, what I would like to do when we click on an element is something like:

listView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.slide_to_left));    
clearAdapter();    
listView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.slide_to_right));    
setItems(newItemList);//Refresh adapter with new items

My problem is that only the second animation is shown.

Any suggestions on what I am doing wrong or why this is not working?

Thank.

Decision

I managed to solve the problem of adding this animation listener.

    Animation animationOut = AnimationUtils.loadAnimation(context, R.anim.slide_to_left);
    animationOut.setAnimationListener(new Animation.AnimationListener() {
        @Override
        public void onAnimationStart(Animation animation) {
            clearAdapter();
        }

        @Override
        public void onAnimationEnd(Animation animation) {
        listView.startAnimation(AnimationUtils.loadAnimation(context, R.anim.slide_to_right));
                setItems(newList);// update content adapter
            }
        }

        @Override
        public void onAnimationRepeat(Animation animation) {

        }
    });
  listView.startAnimation(animationOut);

? , , .

+4
1

( ), , . , Thread.sleep .

0

Source: https://habr.com/ru/post/1532450/


All Articles