Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - ViewSwitcher is not switching views

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()?

like image 810
Bostone Avatar asked Sep 21 '10 18:09

Bostone


1 Answers

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

like image 136
Pavan Jaju Avatar answered Oct 19 '22 06:10

Pavan Jaju