ViewFlipper.showNext() not working in timer

Put your problem here if it does not fit any of the other categories.

ViewFlipper.showNext() not working in timer

Postby andyt » Fri Dec 18, 2009 8:38 pm

I have some webimageviews inside a viewflipper, and I am setting a
timer so that I can play a slideshow of the images. The problem is
the timer function is getting called but the view is not actually
advancing. If I call the viewFlipper.showNext outside of the timer,
the image advances, but not inside the timer. I can't use
viewFlipper.startFlipping because each time it flips I want to
download a new image in the background.

Here's my some of the code:

Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1.  
  2.  
  3.  
  4.  public void playSlideshow() {
  5.  
  6.         Timer updateProgressTimer = null;
  7.  
  8.         updateProgressTimer = new Timer();
  9.  
  10.         int delay = 5000; // delay for 5 sec.
  11.  
  12.  
  13.  
  14.         int period = 5000; // repeat every sec.
  15.  
  16.  
  17.  
  18.         updateProgressTimer.scheduleAtFixedRate(new TimerTask() {
  19.  
  20.  
  21.  
  22.         public void run() {
  23.  
  24.                 System.out.println("done");
  25.  
  26.                 moveRight(viewFlipper);
  27.  
  28.         }
  29.  
  30.  
  31.  
  32.         }, delay, period);
  33.  
  34.  
  35.  
  36.    }
  37.  
  38. }
  39.  
  40.  
  41.  
  42.    public void moveRight(ViewFlipper vf) {
  43.  
  44.         Log.v("moving right", Integer.toString(imageCounter));
  45.  
  46.         Log.v("moving right child", Integer.toString(vf.getDisplayedChild
  47.  
  48. ()));
  49.  
  50.  
  51.  
  52.         vf.setInAnimation(slideLeftIn);
  53.  
  54.        vf.setOutAnimation(slideLeftOut);
  55.  
  56.         vf.showNext();
  57.  
  58. }
  59.  
  60.  
  61.  
  62.  
  63.  
  64.  
Parsed in 0.034 seconds, using GeSHi 1.0.8.4
andyt
Freshman
Freshman
 
Posts: 2
Joined: Fri Dec 18, 2009 8:37 pm

Top

Postby qlimax » Fri Dec 18, 2009 8:58 pm

hi, try it using a handler


Syntax: [ Download ] [ Hide ]
Using java Syntax Highlighting
  1. //create the handler in the onCreate
  2.  
  3. private Handler handler = new Handler() {
  4.  
  5.  
  6.  
  7. @Override
  8.  
  9.  
  10.  
  11. public void handleMessage(Message msg) {
  12.  
  13.  
  14.  
  15. super.handleMessage(msg);
  16.  
  17.  
  18.  
  19. moveRight(viewFlipper);
  20.  
  21.  
  22.  
  23.  
  24.  
  25. }
  26.  
  27.  
  28.  
  29. };
  30.  
  31.  
  32.  
  33.  
  34.  
  35.  
  36.  
  37.  public void playSlideshow() {
  38.  
  39.      Timer updateProgressTimer = null;
  40.  
  41.      updateProgressTimer = new Timer();
  42.  
  43.      int delay = 5000; // delay for 5 sec.
  44.  
  45.  
  46.  
  47.      int period = 5000; // repeat every sec.
  48.  
  49.  
  50.  
  51.      updateProgressTimer.scheduleAtFixedRate(new TimerTask() {
  52.  
  53.  
  54.  
  55.      public void run() {
  56.  
  57.           System.out.println("done");
  58.  
  59.           handler.sendEmptyMessage(0);
  60.  
  61.  
  62.  
  63.      }
  64.  
  65.  
  66.  
  67.      }, delay, period);
  68.  
  69.  
  70.  
  71.    }
  72.  
  73. }
  74.  
  75.  
  76.  
  77.    public void moveRight(ViewFlipper vf) {
  78.  
  79.      Log.v("moving right", Integer.toString(imageCounter));
  80.  
  81.      Log.v("moving right child", Integer.toString(vf.getDisplayedChild
  82.  
  83. ()));
  84.  
  85.  
  86.  
  87.      vf.setInAnimation(slideLeftIn);
  88.  
  89.        vf.setOutAnimation(slideLeftOut);
  90.  
  91.      vf.showNext();
  92.  
  93. }
Parsed in 0.034 seconds, using GeSHi 1.0.8.4


let me know...
bye ;)
¯`·.¸¸.><((((º>¯`·.¸¸. ><((((º>
User avatar
qlimax
Master Developer
Master Developer
 
Posts: 271
Joined: Mon Aug 31, 2009 10:54 am
Location: Swiss

Postby andyt » Fri Dec 18, 2009 9:15 pm

thanks for the quick reply and sample code, that worked!
andyt
Freshman
Freshman
 
Posts: 2
Joined: Fri Dec 18, 2009 8:37 pm

Top

Return to Other Coding-Problems

Who is online

Users browsing this forum: No registered users and 26 guests