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);
}
}
@Override
public void onAnimationRepeat(Animation animation) {
}
});
listView.startAnimation(animationOut);
? , , .