Android APIs
public class

ViewSwitcher

extends ViewAnimator
java.lang.Object
   ↳ android.view.View
     ↳ android.view.ViewGroup
       ↳ android.widget.FrameLayout
         ↳ android.widget.ViewAnimator
           ↳ android.widget.ViewSwitcher
Known Direct Subclasses

Class Overview

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. 
[Expand]
Inherited XML Attributes
From class android.widget.ViewAnimator
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Constants
From class android.view.ViewGroup
From class android.view.View
[Expand]
Inherited Fields
From class android.view.View
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.
View getNextView()
Returns the next view to be displayed.
void onInitializeAccessibilityEvent(AccessibilityEvent event)
Initializes an AccessibilityEvent with information about this View which is the event source.
void onInitializeAccessibilityNodeInfo(AccessibilityNodeInfo info)
Initializes an AccessibilityNodeInfo with information about this view.
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.
[Expand]
Inherited Methods
From class android.widget.ViewAnimator
From class android.widget.FrameLayout
From class android.view.ViewGroup
From class android.view.View
From class java.lang.Object
From interface android.graphics.drawable.Drawable.Callback
From interface android.view.KeyEvent.Callback
From interface android.view.ViewManager
From interface android.view.ViewParent
From interface android.view.accessibility.AccessibilityEventSource

Public Constructors

public ViewSwitcher (Context context)

Added in API level 1

Creates a new empty ViewSwitcher.

Parameters
context the application's environment

public ViewSwitcher (Context context, AttributeSet attrs)

Added in API level 1

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

Parameters
context the application environment
attrs a collection of attributes

Public Methods

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

Added in API level 1

Adds a child view with the specified layout parameters.

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

Parameters
child the child view to add
index the position at which to add the child
params the layout parameters to set on the child
Throws
IllegalStateException if this switcher already contains two children

public View getNextView ()

Added in API level 1

Returns the next view to be displayed.

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

public void onInitializeAccessibilityEvent (AccessibilityEvent event)

Added in API level 14

Initializes an AccessibilityEvent with information about this View which is the event source. In other words, the source of an accessibility event is the view whose state change triggered firing the event.

Example: Setting the password property of an event in addition to properties set by the super implementation:

 public void onInitializeAccessibilityEvent(AccessibilityEvent event) {
     super.onInitializeAccessibilityEvent(event);
     event.setPassword(true);
 }

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityEvent(View, AccessibilityEvent) is responsible for handling this call.

Note: Always call the super implementation before adding information to the event, in case the default implementation has basic information to add.

Parameters
event The event to initialize.

public void onInitializeAccessibilityNodeInfo (AccessibilityNodeInfo info)

Added in API level 14

Initializes an AccessibilityNodeInfo with information about this view. The base implementation sets:

Subclasses should override this method, call the super implementation, and set additional attributes.

If an View.AccessibilityDelegate has been specified via calling setAccessibilityDelegate(AccessibilityDelegate) its onInitializeAccessibilityNodeInfo(View, AccessibilityNodeInfo) is responsible for handling this call.

Parameters
info The instance to initialize.

public void reset ()

Added in API level 1

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

public void setFactory (ViewSwitcher.ViewFactory factory)

Added in API level 1

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 the view factory used to generate the switcher's content