Android - ViewSwitcher does not switch views

It should be easy, right? So - this is how I defined ViewSwitcherin XML (Id and layouts omitted for brevity)

<ViewSwitcher android:layout_height="wrap_content" android:layout_width="fill_parent" >       
    <!-- First view, comes up OK --> 
    <LinearLayout android:id="@+id/header1">
        <!-- some more controls: Progress bar, test view and the button -->
    </LinearLayout>
    <!-- second view. changing to the actual (not include) layout has no effect -->
    <include android:id="@+id/header2" />
</ViewSwitcher>

Then somewhere in my Java code I have this code

ViewSwitcher switcher = (ViewSwitcher) findViewById(R.id.profileSwitcher);
// more code that basically executes background search
// when call comes back - switch
switcher.bringToFront(); // does nothing
// switcher.bringChildToFront(findViewById(R.id.header2)); // no effect ether

He just doesn't switch. I am developing for API v. 3 (1.5+), and, to my surprise, there are very few links to ViewSwitcher. Did I miss something obvious here?

PS I just discovered by brute force that this works:

switcher.setDisplayedChild(1);

However - why not luck with bringToFront()?

+3
source share
2 answers

bringToFront() ViewSwitcher, View z-: https://developer.android.com/reference/android/view/View.html#bringToFront()

showNext() showPrevious(), ViewAnimator.

+18

ViewSwitcher showPrevious() showNext()

setDisplayedChild(int index), 0, 1

+13

Source: https://habr.com/ru/post/1765863/


All Articles