ViewSwitcher

public class ViewSwitcher
extends ViewAnimator

java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ android.widget.ViewAnimator
           ↳ android.widget.ViewSwitcher


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.

Summary

Nested classes

interface ViewSwitcher.ViewFactory

Creates views in a ViewSwitcher. 

Inherited XML attributes

Inherited constants

Inherited fields

Public constructors

ViewSwitcher(Context context)

Creates a new empty ViewSwitcher.

ViewSwitcher(Context context, AttributeSet attrs)

Creates a new empty ViewSwitcher for the given context and with the specified set attributes.

Public methods

void addView(View child, int index, ViewGroup.LayoutParams params)

Adds a child view with the specified layout parameters.

CharSequence getAccessibilityClassName()

Return the class name of this object to be used for accessibility purposes.

View getNextView()

Returns the next view to be displayed.

void reset()

Reset the ViewSwitcher to hide all of the existing views and to make it think that the first time animation has not yet played.

void setFactory(ViewSwitcher.ViewFactory factory)

Sets the factory used to create the two views between which the ViewSwitcher will flip.

Inherited methods

Public constructors

ViewSwitcher

Added in API level 1
public ViewSwitcher (Context context)

Creates a new empty ViewSwitcher.

Parameters
context Context: the application's environment

ViewSwitcher

Added in API level 1
public ViewSwitcher (Context context, 
                AttributeSet attrs)

Creates a new empty ViewSwitcher for the given context and with the specified set attributes.

Parameters
context Context: the application environment

attrs AttributeSet: a collection of attributes

Public methods

addView

Added in API level 1
public void addView (View child, 
                int index, 
                ViewGroup.LayoutParams params)

Adds a child view with the specified layout parameters.

Note: do not invoke this method from View.draw(android.graphics.Canvas), View.onDraw(android.graphics.Canvas), dispatchDraw(android.graphics.Canvas) or any related method.

Parameters
child View: the child view to add

index int: the position at which to add the child or -1 to add last

params ViewGroup.LayoutParams: the layout parameters to set on the child

Throws
IllegalStateException if this switcher already contains two children

getAccessibilityClassName

Added in API level 23
public CharSequence getAccessibilityClassName ()

Return the class name of this object to be used for accessibility purposes. Subclasses should only override this if they are implementing something that should be seen as a completely new class of view when used by accessibility, unrelated to the class it is deriving from. This is used to fill in AccessibilityNodeInfo.setClassName.

Returns
CharSequence

getNextView

Added in API level 1
public View getNextView ()

Returns the next view to be displayed.

Returns
View the view that will be displayed after the next views flip.

reset

Added in API level 1
public void reset ()

Reset the ViewSwitcher to hide all of the existing views and to make it think that the first time animation has not yet played.

setFactory

Added in API level 1
public void setFactory (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 addView(android.view.View, int, android.view.ViewGroup.LayoutParams) twice.

Parameters
factory ViewSwitcher.ViewFactory: the view factory used to generate the switcher's content