title: ListView animation. Only 1 of 2 animations working
body: <p>I have a <code>ListView</code> in which when I click on a row item header, it expands (with animation) and shows some more info below it. When clicking the row item header again, it is supposed to play another animation which shrinks it.</p>
  
  <p>The expanding animation is working fine, but the shrink animation is not working at all.</p>
  
  <p><strong>Why is only the <code>expandDownAnim</code> working and not the <code>shrinkUpAnim</code>?</strong></p>
  
  <p><strong>ListView Row XML</strong></p>
  
  <pre><code>&lt;LinearLayout
  xmlns:android="http://schemas.android.com/apk/res/android"
  android:layout_width="match_parent"
  android:layout_height="wrap_content"
  android:orientation="vertical"&gt;
  
  &lt;View
      android:layout_width="match_parent"
      android:layout_height="1dp"
      android:background="@color/horizontal_line" /&gt;
  
  &lt;LinearLayout
      android:id="@+id/header"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="horizontal"
      android:background="@color/schedule_header_bg"
      android:padding="10dp" &gt;
  
      &lt;com.walintukai.lfdate.widgets.CustomTextView
          android:id="@+id/day"
          android:layout_width="0dp"
          android:layout_height="wrap_content"
          android:layout_weight="1"
          android:layout_gravity="center_vertical"
          android:textStyle="bold"
          android:textAllCaps="true"
          android:textSize="18sp"
          android:textColor="@color/secondary_blue" /&gt;
  
      &lt;com.walintukai.lfdate.widgets.CustomTextView
          android:id="@+id/is_active"
          android:layout_width="34dp"
          android:layout_height="24dp"
          android:layout_gravity="center_vertical"
          android:gravity="center"
          android:textAllCaps="true"
          android:textStyle="bold"
          android:textColor="#fff"
          android:textSize="12sp"
          android:background="@drawable/bg_gray_radius" /&gt;
  
  &lt;/LinearLayout&gt;
  
  &lt;View
      android:layout_width="match_parent"
      android:layout_height="1dp"
      android:background="@color/horizontal_line" /&gt;
  
  &lt;LinearLayout
      android:id="@+id/container"
      android:layout_width="match_parent"
      android:layout_height="wrap_content"
      android:orientation="vertical"
      android:background="#fff"
      android:paddingTop="10dp"
      android:paddingBottom="10dp"
      android:paddingLeft="4dp"
      android:paddingRight="4dp"&gt;
  
      &lt;RelativeLayout
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          android:layout_marginLeft="16dp"
          android:layout_marginRight="16dp" &gt;
  
          &lt;LinearLayout
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:orientation="vertical"
              android:layout_alignParentLeft="true" &gt;
  
              &lt;com.walintukai.lfdate.widgets.CustomTextView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center"
                  android:textSize="15sp"
                  android:text="@string/start" /&gt;
  
              &lt;com.walintukai.lfdate.widgets.CustomTextView
                  android:id="@+id/start_time"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center"
                  android:textStyle="bold"
                  android:textSize="19sp" /&gt;
  
          &lt;/LinearLayout&gt;
  
          &lt;LinearLayout
              android:layout_width="wrap_content"
              android:layout_height="wrap_content"
              android:orientation="vertical"
              android:layout_alignParentRight="true" &gt;
  
              &lt;com.walintukai.lfdate.widgets.CustomTextView
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center"
                  android:textSize="15sp"
                  android:text="@string/end" /&gt;
  
              &lt;com.walintukai.lfdate.widgets.CustomTextView
                  android:id="@+id/end_time"
                  android:layout_width="wrap_content"
                  android:layout_height="wrap_content"
                  android:layout_gravity="center"
                  android:textStyle="bold"
                  android:textSize="19sp" /&gt;
  
          &lt;/LinearLayout&gt;
  
      &lt;/RelativeLayout&gt;
  
      &lt;com.edmodo.rangebar.RangeBar
          xmlns:custom="http://schemas.android.com/apk/res-auto"
          android:id="@+id/rangebar"
          android:layout_width="match_parent"
          android:layout_height="wrap_content"
          custom:tickHeight="0dp"
          custom:tickCount="24" /&gt;
  
  &lt;/LinearLayout&gt;
  </code></pre>
  
  <p></p>
  
  <p><strong>BaseAdapter which has the animations (shortened)</strong></p>
  
  <pre><code>@Override
  public View getView(final int position, View convertView, ViewGroup parent) {
      final ViewHolder holder;
  
      if (convertView == null) {
          holder = new ViewHolder();
          convertView = mInflater.inflate(R.layout.row_schedule, null);
          holder.header = (LinearLayout) convertView.findViewById(R.id.header);
          holder.day = (CustomTextView) convertView.findViewById(R.id.day);
          holder.isActive = (CustomTextView) convertView.findViewById(R.id.is_active);
          holder.container = (LinearLayout) convertView.findViewById(R.id.container);
          holder.rangeBar = (RangeBar) convertView.findViewById(R.id.rangebar);
          holder.tvStartTime = (CustomTextView) convertView.findViewById(R.id.start_time);
          holder.tvEndTime = (CustomTextView) convertView.findViewById(R.id.end_time);
          convertView.setTag(holder);
      }
      else {
          holder = (ViewHolder) convertView.getTag();
      }
  
      if (mSchedules.get(position).getDate() != null &amp;&amp; !mSchedules.get(position).getDate().isEmpty())
          holder.day.setText(getFormattedDate(mSchedules.get(position).getDate()));
  
      if (mSchedules.get(position).getIsActive()) {
          holder.isActive.setText(R.string.btn_on);
          holder.isActive.setBackgroundResource(R.drawable.bg_green_radius);
          holder.container.setVisibility(View.VISIBLE);
      }
      else {
          holder.isActive.setText(R.string.btn_off);
          holder.isActive.setBackgroundResource(R.drawable.bg_gray_radius);
          holder.container.setVisibility(View.GONE);
      }
  
      holder.header.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if (mSchedules.get(position).getIsActive()) {
                  mSchedules.get(position).setIsActive(false);
  
                  Animation anim = AnimationUtils.loadAnimation(mContext, R.anim.shrink_up);
                  anim.setDuration(300);
  
                  holder.container.setVisibility(View.GONE);
                  holder.container.setAnimation(anim);
                  holder.container.animate();
                  anim.start();
  
                  holder.isActive.setText(R.string.btn_off);
                  holder.isActive.setBackgroundResource(R.drawable.bg_gray_radius);
              }
              else {
                  mSchedules.get(position).setIsActive(true);
  
                  Animation anim = AnimationUtils.loadAnimation(mContext, R.anim.expand_down);
                  anim.setDuration(300);
  
                  holder.container.setVisibility(View.VISIBLE);
                  holder.container.setAnimation(anim);
                  holder.container.animate();
                  anim.start();
  
                  holder.isActive.setText(R.string.btn_on);
                  holder.isActive.setBackgroundResource(R.drawable.bg_green_radius);
              }
          }
      });
  
      final DateTimeFormatter timeFormatter = DateTimeFormat.forPattern("hh:mm a");
  
      int startTime = mSchedules.get(position).getStartTime();
      int endTime = mSchedules.get(position).getEndTime();
  
      LocalTime localStartTime = new LocalTime(startTime, 0, 0);
      LocalTime localEndTime = new LocalTime(endTime, 0, 0);
  
      holder.tvStartTime.setText(timeFormatter.print(localStartTime));
      holder.tvEndTime.setText(timeFormatter.print(localEndTime));
      holder.rangeBar.setThumbIndices(startTime, endTime);
  
      holder.rangeBar.setOnRangeBarChangeListener(new RangeBar.OnRangeBarChangeListener() {
          @Override
          public void onIndexChangeListener(RangeBar rangeBar, int leftThumbIndex, int rightThumbIndex) {
              mSchedules.get(position).setStartTime(leftThumbIndex);
              mSchedules.get(position).setEndTime(rightThumbIndex);
  
              LocalTime localStartTime = new LocalTime(leftThumbIndex, 0, 0);
              LocalTime localEndTime = new LocalTime(rightThumbIndex, 0, 0);
  
              holder.tvStartTime.setText(timeFormatter.print(localStartTime));
              holder.tvEndTime.setText(timeFormatter.print(localEndTime));
          }
      });
  
      return convertView;
  }
  </code></pre>
  
  <p><strong>UPDATE 1: added AnimationListener</strong></p>
  
  <p>Added an <code>AnimationListener</code> to my animation, but now when I click to close a row, it gets stuck and only will close if I click another row that is currently closed. Then all the rows that were supposed to close would all close at the same time (triggered by the click of the row that is currently closed).</p>
  
  <pre><code>holder.header.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View v) {
              if (mSchedules.get(position).getIsActive()) {
                  mSchedules.get(position).setIsActive(false);
  
                  Animation anim = AnimationUtils.loadAnimation(mContext, R.anim.shrink_up);
                  anim.setDuration(300);
                  anim.setAnimationListener(new Animation.AnimationListener() {
                      @Override
                      public void onAnimationStart(Animation animation) {
                      }
  
                      @Override
                      public void onAnimationEnd(Animation animation) {
                          holder.container.setVisibility(View.GONE);
                      }
  
                      @Override
                      public void onAnimationRepeat(Animation animation) {
                      }
                  });
  
                  holder.container.setAnimation(anim);
                  holder.container.animate();
                  anim.start();
  
                  holder.isActive.setText(R.string.btn_off);
                  holder.isActive.setBackgroundResource(R.drawable.bg_gray_radius);
              }
              else {
                  mSchedules.get(position).setIsActive(true);
  
                  Animation anim = AnimationUtils.loadAnimation(mContext, R.anim.expand_down);
                  anim.setDuration(300);
  
                  holder.container.setVisibility(View.VISIBLE);
                  holder.container.setAnimation(anim);
                  holder.container.animate();
                  anim.start();
  
                  holder.isActive.setText(R.string.btn_on);
                  holder.isActive.setBackgroundResource(R.drawable.bg_green_radius);
              }
          }
      });
  </code></pre>