1

I'm using listview animation from API DEMOS, example 2. here's the snippet from OnCreate method:

ListView listview = (ListView) findViewById(android.R.id.list);

AnimationSet set = new AnimationSet(true);
Animation animation = new AlphaAnimation(0.0f, 1.0f);
animation.setDuration(50);
set.addAnimation(animation);

animation = new TranslateAnimation(
    Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f,
    Animation.RELATIVE_TO_SELF, -1.0f, Animation.RELATIVE_TO_SELF, 0.0f);

animation.setDuration(200);
set.addAnimation(animation);

LayoutAnimationController controller = new LayoutAnimationController(set, 0.5f);
listview.setLayoutAnimation(controller);

At some point in the future, notifyDataSetInvalidated() is called upon list's adapter, and my list is refreshed. but the items are not shown in animation any more.

Please help.

Nikhil Agrawal
  • 26,128
  • 21
  • 90
  • 126
Tomislav Novoselec
  • 4,570
  • 2
  • 27
  • 22

2 Answers2

3

If you want to reanimate your LayoutController after your data set changes, call the method startLayoutAnimation() of the view.

Makario
  • 2,097
  • 21
  • 19
  • this is for a viewgroup. If I want, for example, to replay the animation on a recycled view y cant call View.startLayoutAnimation() . It doesn't exist – dinigo Sep 13 '12 at 23:34
0

You should check out this thread about difference between notifyDataSetChanged() and notifyDataSetInvalidated() (Link updated to point to Romain Guy's answer!)

In short the difference is:

  • notifyDataSetChanged: The items in the data set are changed (added / removed / updated / reordered, whatever).
  • notifyDataSetInvalidated: The data source of the adapter is no longer available.

Here you can find a working sample with notifyDataSetInvalidated function in use. Probably it will do the trick with your animation problem as well.

Community
  • 1
  • 1
rekaszeru
  • 19,130
  • 7
  • 59
  • 73