1. Check out our companion app, Forums for Android! Download from Google Play

Problems with ViewSwitcher

Discussion in 'Application Development' started by grtabor, Dec 2, 2010.

  1. grtabor

    grtabor New Member
    Thread Starter
    5

    Dec 2, 2010
    1
    0
    5
    Hi everyone.

    I'm trying to automatically switch between two views on the screen; as part of a game, when the user hits the right button, the view needs to switch to display the result, and then automatically return after (say) 5 seconds. I've tried various things, but none of them seem to work as advertised. Currently I'm using ViewSwitcher, with the two views set up in xml; and using the following to switch:

    try{
    swap.showNext();
    Thread.sleep(1000);
    Log.d("GRT:","In here");

    }
    catch (InterruptedException e){}
    finally{
    Log.d("GRT:","In here2");
    swap.showPrevious();
    }

    swap is the ViewSwitcher set up with two views.
    To my understanding, this should switch views, wait for 1000 ms, then switch back again. Logcat shows that the code is entering the try and finally blocks, with an appropriate pause between them (I get the messages in the adb logcat file) but the display doesn't change. Switching manually (just calling swap.showNext()) _does_ change the display, so AFAICT its not related to the actual View being displayed.

    Any suggestions as to what I am doing wrong gratefully received.
     

    Advertisement

  2. jonbonazza

    jonbonazza Well-Known Member
    163

    Jul 13, 2010
    1,934
    458
    163
    Male
    Try implementing a timer instead of Thread.sleep().
     

Share This Page

Loading...