2

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?

parsley72
  • 8,449
  • 8
  • 65
  • 98
Roman
  • 2,079
  • 4
  • 35
  • 53

1 Answers1

6

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.

DArkO
  • 15,880
  • 12
  • 60
  • 88
  • 1
    sweet just changed `` with `` and everything works fine without need of changing a single line of code . with that not sure what is the point of having ViewSwitcher as ViewFlipper does all ViewSwitcher do and more. – bastami82 Jul 23 '19 at 12:03