FileDocCategorySizeDatePackage
ViewSwitcher.javaAPI DocAndroid 1.5 API3975Wed May 06 22:41:56 BST 2009android.widget

ViewSwitcher

public class ViewSwitcher extends ViewAnimator
{@link ViewAnimator} that switches between two views, and has a factory from which these views are created. You can either use the factory to create the views, or add them yourself. A ViewSwitcher can only have two child views, of which only one is shown at a time.

Fields Summary
ViewFactory
mFactory
The factory used to create the two children.
Constructors Summary
public ViewSwitcher(android.content.Context context)
Creates a new empty ViewSwitcher.

param
context the application's environment

        super(context);
    
public ViewSwitcher(android.content.Context context, android.util.AttributeSet attrs)
Creates a new empty ViewSwitcher for the given context and with the specified set attributes.

param
context the application environment
param
attrs a collection of attributes

        super(context, attrs);
    
Methods Summary
public voidaddView(android.view.View child, int index, ViewGroup.LayoutParams params)
{@inheritDoc}

throws
IllegalStateException if this switcher already contains two children

        if (getChildCount() >= 2) {
            throw new IllegalStateException("Can't add more than 2 views to a ViewSwitcher");
        }
        super.addView(child, index, params);
    
public android.view.ViewgetNextView()
Returns the next view to be displayed.

return
the view that will be displayed after the next views flip.

        int which = mWhichChild == 0 ? 1 : 0;
        return getChildAt(which);
    
private android.view.ViewobtainView()

        View child = mFactory.makeView();
        LayoutParams lp = (LayoutParams) child.getLayoutParams();
        if (lp == null) {
            lp = new LayoutParams(LayoutParams.FILL_PARENT, LayoutParams.WRAP_CONTENT);
        }
        addView(child, lp);
        return child;
    
public voidreset()
Reset the ViewSwitcher to hide all of the existing views and to make it think that the first time animation has not yet played.

        mFirstTime = true;
        View v;
        v = getChildAt(0);
        if (v != null) {
            v.setVisibility(View.GONE);
        }
        v = getChildAt(1);
        if (v != null) {
            v.setVisibility(View.GONE);
        }
    
public voidsetFactory(android.widget.ViewSwitcher$ViewFactory factory)
Sets the factory used to create the two views between which the ViewSwitcher will flip. Instead of using a factory, you can call {@link #addView(android.view.View, int, android.view.ViewGroup.LayoutParams)} twice.

param
factory the view factory used to generate the switcher's content

        mFactory = factory;
        obtainView();
        obtainView();