Note that there are some explanatory texts on larger screens.

plurals
  1. POViewAnimator's OnDraw throws NullPointerException if you remove child on onAnimationEnd
    text
    copied!<p>This is not a question, more like sharing with others a problem I encountered and how I resolved it. <br/> Basically, I was trying to create a ViewAnimator, who would create additional children in response to user clicks.<br/> To clean up after I have animated the next View in, I put</p> <pre><code>outAnimation.setAnimationListener(listener); </code></pre> <p>and in AnimationListener</p> <pre><code>public void onAnimationEnd(Animation animation) { viewAnimator.removeView(out); } </code></pre> <p>Now, the problem with above approach is, immediately after onAnimationEnd, it throws a NullPointerException. Basically, it means, ViewAnimator is still using child view that is being animated out to draw. Since I have removed it, there is null there. I have done my research, and basically, it appears this is a known bug. See: <a href="https://stackoverflow.com/questions/4750939/android-animation-is-not-finished-in-onanimationend">Android Animation is not finished on onAnimationEnd</a> <br> <br> To resolve this, I have modified layout.</p> <pre><code>&lt;ViewAnimator android:id="@+id/animator" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;FrameLayout android:id="@+id/container1" android:layout_width="fill_parent" android:layout_height="fill_parent"&gt; &lt;/FrameLayout&gt; &lt;FrameLayout android:id="@+id/container2" android:layout_width="fill_parent" android:layout_height="fill_parent" &gt; &lt;/FrameLayout&gt; &lt;/ViewAnimator&gt; </code></pre> <p>and onAnimationEnd I can safely call <code>container.removeAllViews()</code>. To animate a new view in, I select the hidden container and</p> <pre><code>container.addView(newView); animator.setDisplayedChild(animator.indexOfChild(container)); </code></pre> <p>I will be happy to see your comments and advice.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload