It should be easy, right? So - here's how I have ViewSwitcher defined in XML (Id's 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
It's just not switching. I develop for API v. 3 (1.5+) and to my surprise there are very few references to ViewSwitcher. I'm I missing something obvious here?
P.S. I just found out by brute force that this works:
switcher.setDisplayedChild(1);
Still - why no luck with bringToFront()?
In ViewSwitcher to navigate between views you can use the methods showPrevious() and showNext()
Or use also can go to specific view by setDisplayedChild(int index) method where index can be either 0 or 1
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With