FileDocCategorySizeDatePackage
TextSwitcher.javaAPI DocAndroid 1.5 API2805Wed May 06 22:41:56 BST 2009android.widget

TextSwitcher

public class TextSwitcher extends ViewSwitcher
Specialized {@link android.widget.ViewSwitcher} that contains only children of type {@link android.widget.TextView}. A TextSwitcher is useful to animate a label on screen. Whenever {@link #setText(CharSequence)} is called, TextSwitcher animates the current text out and animates the new text in.

Fields Summary
Constructors Summary
public TextSwitcher(android.content.Context context)
Creates a new empty TextSwitcher.

param
context the application's environment

        super(context);
    
public TextSwitcher(android.content.Context context, android.util.AttributeSet attrs)
Creates a new empty TextSwitcher 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
IllegalArgumentException if child is not an instance of {@link android.widget.TextView}

        if (!(child instanceof TextView)) {
            throw new IllegalArgumentException(
                    "TextSwitcher children must be instances of TextView");
        }

        super.addView(child, index, params);
    
public voidsetCurrentText(java.lang.CharSequence text)
Sets the text of the text view that is currently showing. This does not perform the animations.

param
text the new text to display

        ((TextView)getCurrentView()).setText(text);
    
public voidsetText(java.lang.CharSequence text)
Sets the text of the next view and switches to the next view. This can be used to animate the old text out and animate the next text in.

param
text the new text to display

        final TextView t = (TextView) getNextView();
        t.setText(text);
        showNext();