Set the displayed child of an animator view by the view resource ID. - Android android.animation

Android examples for android.animation:Animator

Description

Set the displayed child of an animator view by the view resource ID.

Demo Code


//package com.java2s;
import android.view.View;
import android.widget.ViewAnimator;

public class Main {
    /**/*  ww w.  j av a  2s.c o  m*/
     * Set the displayed child of an animator view by the view resource ID.
     * If the animator has no child with the given resource ID, nothing happens.
     * @param animator the animator the view to display is in. Must not be null
     * @param viewResource the resource ID of the view to display
     */
    public static void setAnimatorDisplayedChild(
            final ViewAnimator animator, final int viewResource) {
        final View view = animator.findViewById(viewResource);
        if (view != null) {
            final int viewIndexInParent = animator.indexOfChild(view);
            if (viewIndexInParent >= 0)
                animator.setDisplayedChild(viewIndexInParent);
        }
    }
}

Related Tutorials