title: Animations inside a ListView
body: <p>I'm trying to animate a view from time to time inside an item of a <code>ListView</code>. It is a custom view, it extends <code>RelativeLayout</code>, and its purpose is to get some information from time to time from several sources (including internet), and to display it.
  Whenever new information is available, a new child view is created programatically. The old view is animated out of the custom view (RelativeLayout), while the new view is animated in, exactly as a ViewFlipper works.
  This view works fine when placed in regular layouts, but I have issues when placing it into a ListView's item. The issue is that it stops redrawing itself after one or two scrolls on the list - right after it gets out of the screen and comes back again. The animations are not visible anymore and the custom view only gets drawn when interacting with the list.
  I tried invalidating the view, invalidating the list and other options, however, this does not work...</p>
  
  <p>Any help is greatly appreciated. Thanks.</p>
  
  <p>Here is some code resembling the exact mechanism I tried for my custom view (here I used a ViewFlipper to check if something is wrong with my view. Apparently it behaves the same, the flipper is not redrawn after interacting with the list)</p>
  
  <pre><code>package com.test.viewflipper;
  
  import android.app.ListActivity;
  import android.os.Bundle;
  import android.view.LayoutInflater;
  import android.view.View;
  import android.view.ViewGroup;
  import android.view.ViewGroup.LayoutParams;
  import android.view.animation.Animation;
  import android.view.animation.TranslateAnimation;
  import android.widget.AbsListView;
  import android.widget.BaseAdapter;
  import android.widget.Button;
  import android.widget.TextView;
  import android.widget.ViewFlipper;
  
  public class ViewFlipperTestActivity extends ListActivity {
    /** Called when the activity is first created. */
  
    private ViewFlipper viewFlipper;
    private Animation TRANSLATE_LEFT_TO_RIGHT_VIEW_IN = new TranslateAnimation(Animation.RELATIVE_TO_SELF, -1.0f,
        Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f);
    private Animation TRANSLATE_LEFT_TO_RIGHT_VIEW_OUT = new TranslateAnimation(Animation.RELATIVE_TO_SELF, 0.0f,
        Animation.RELATIVE_TO_SELF, 1.0f, Animation.RELATIVE_TO_SELF, 0.0f, Animation.RELATIVE_TO_SELF, 0.0f);
  
    @Override
    public void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
  
      viewFlipper = new ViewFlipper(this);
      LayoutParams params = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
      viewFlipper.setLayoutParams(new AbsListView.LayoutParams(params));
      viewFlipper.setInAnimation(TRANSLATE_LEFT_TO_RIGHT_VIEW_IN);
      viewFlipper.setOutAnimation(TRANSLATE_LEFT_TO_RIGHT_VIEW_OUT);
      for (int i = 0; i &lt; 10; i++) {
        Button button = new Button(getApplicationContext());
        button.setText("Button " + i);
        viewFlipper.addView(button);
      }
      viewFlipper.setFlipInterval(1000);
      viewFlipper.setAutoStart(true);
      viewFlipper.startFlipping();
  
      LayoutInflater layoutInflater = (LayoutInflater) getSystemService(LAYOUT_INFLATER_SERVICE);
      setListAdapter(new AdListAdapter(layoutInflater));
    }
  
    private class AdListAdapter extends BaseAdapter {
  
      private LayoutInflater layoutInflater;
  
      public AdListAdapter(LayoutInflater layoutInflater) {
        this.layoutInflater = layoutInflater;
      }
  
      @Override
      public int getCount() {
        return 10;
      }
  
      @Override
      public Object getItem(int position) {
        return null;
      }
  
      @Override
      public long getItemId(int position) {
        return 0;
      }
  
      @Override
      public View getView(int position, View convertView, ViewGroup parent) {
        /* return the ad container for the first position */
        if (position == 0) {
          return viewFlipper;
        }
        else {
          View view = layoutInflater.inflate(android.R.layout.simple_list_item_1, null);
          TextView textView = (TextView) view.findViewById(android.R.id.text1);
          textView.setText("Item " + position);
          return view;
        }
      }
    }
  }
  </code></pre>