Question

I use ViewSwitcher like this:

<ViewSwitcher
    android:layout_width="wrap_content"
    android:layout_height="wrap_content"
    android:id="@+id/content_popup"
    android:visibility="invisible"
    android:layout_centerInParent="true">

    <include layout="@layout/content_popup_stub" android:id="@+id/content_general"/>
    <include layout="@layout/video_select_popup_stub" android:id="@+id/content_select_video"/>

</ViewSwitcher>   

And plan to use 4 children more in that ViewSwitcher. Now, how to switch between say view1 and view 4, or view1 and view3 using .showNext() or .showPrevious()? Is there a way to set what view goes next or previous?

Was it helpful?

Solution

The documentation found here:

http://developer.android.com/reference/android/widget/ViewSwitcher.html

States that the view switcher is a component that switches between 2 views (not more than 2). If you want to switch between more than 2 views then i suggest you use a ViewFlipper

http://developer.android.com/reference/android/widget/ViewFlipper.html

which is extended from ViewAnimator. it has a method called setDisplayedChild

(http://developer.android.com/reference/android/widget/ViewAnimator.html#setDisplayedChild(int))

which you can use to animate between the different views you have. it has pretty much the same implementation as the ViewSwitcher.

Hope this helps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top