Calco Calco - 1 year ago 94
Android Question

How to start animation contained with a custom layout

I am trying to start an animation which is contained within a custom layout. This layout is used for each row of a listview. The animation works fine if moved outside of this custom layout, so the problem does not seem to lie with images/xml files.

I believe the issue lies with how I am calling the animation. for example the standard code to start an animation works (so not using the custom layout):

ImageView mImageViewEmptying = (ImageView) findViewById(;
((AnimationDrawable) mImageViewEmptying.getBackground()).start();

But now I if I want to start the animation contained within the custom layout I then (the following is potentially wrong!) inflate the custom layout into a view, then do the same as before:

LayoutInflater inflater = this.getLayoutInflater();
View dialogView = inflater.inflate(R.layout.custom_listview_activetethers, null);

ImageView mImageViewFilling = (ImageView) dialogView.findViewById(;
((AnimationDrawable) mImageViewFilling.getBackground()).start();

Now this must be wrong, as it doesn't actually do anything. I can see the first frame of the animation on the screen, but the above code doesn't seem to start it. Any ideas where I am going wrong?

Answer Source

The solution was to create a custom list adapter class and override getView to carry out the methods required. Then in the activity that contains the listview, create an ArrayAdapter of the custom list adapter. Finally, set the listview's adapter as the ArrayAdapter object.

All custom functionality can now be controlled via the custom list adapter class, and it will show within the activity's listview.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download