2009-12-28 4 views
0

Je développe une application dans le développement de blackberry java. Je demande à http signifie que je me connecte à la réponse du service Web. Le service Web prend un certain temps. À ce moment, je veux afficher un écran d'attente.BlackBerry - écran d'attente

Pourriez-vous me dire comment puis-je faire ....

Cordialement Pankaj Pareek

+0

Je viens de trouver des messages cela pourrait vous être utile (si vous ne les avez pas déjà vues). http://www.blackberryforums.com/developer-forum/63182-simple-please-wait-screen.html – Alex

Répondre

1

Fondamentalement, vous devez commencer à la demande du réseau dans un thread d'arrière-plan. Une fois l'opération réseau terminée, vous devez notifier l'unité d'exécution principale/interface utilisateur pour que l'écran d'attente apparaisse dans les résultats.

Pour informer le fil conducteur de jeter un oeil sur le lien ci-dessous et la recherche de invokeLater:
http://developers.sun.com/mobility/midp/articles/blackberrydev/

conseil: Ne pas se reproduire à plusieurs threads à la fois sur les appareils mobiles. Habituellement, ils ont un nombre de threads vraiment bas.

0

faire une chose .... Lors de l'événement listner de bouton écrire ceci.

  UiApplication.getUiApplication().invokeLater(new Runnable(){ 
      public void run(){ 
      Status.show("Please Wait....",b,3600); 
      message.setText(test(theFile)); 
      } 
     }); 
0

J'ai créé un champ bitmap d'animation personnalisée, comme ceci:

// Classe fil

public class AnimatedImageField extends BitmapField implements Runnable 
{ 

private Thread thread = null; 
private boolean animate=true; 
private int interval = 0; 
private int index=0; 
private Bitmap bitmap = null; 
private int frameno = 0; 
private int fieldHeight=0; 
private int fieldWidth=0; 
private Bitmap finalbitmap = null; 
private int imgHeight = 0; 
private int imgWidth= 0; 

public AnimatedImageField(int fieldwidth, int fieldheight, Bitmap bitmap, int frameno, int interval, long style) 
{ 
    super(bitmap, style); 
    this.interval=interval; 
    this.bitmap=bitmap; 
    this.frameno=frameno; 
    imgHeight = bitmap.getHeight(); 
    int imgwidth = bitmap.getWidth(); 
    imgWidth=imgwidth/frameno; 
    this.fieldWidth = fieldwidth; 
    this.fieldHeight = fieldheight; 
} 

public AnimatedImageField(Bitmap bitmap, int frameno, int interval, long style) 
{ 
    super(bitmap, style); 
    this.interval=interval; 
    this.bitmap=bitmap; 
    this.frameno=frameno; 
    imgHeight = bitmap.getHeight(); 
    int imgwidth = bitmap.getWidth(); 
    imgWidth=imgwidth/frameno; 
    fieldWidth = imgWidth; 
    fieldHeight = imgHeight; 
} 

protected void paint(Graphics graphics){ 
    graphics.setColor(Color.WHITE); 
    graphics.fillRect(0,0,this.getPreferredWidth(), this.getPreferredHeight()); 

    //System.out.println("animate:"+animate); 
    if (animate) 
     graphics.drawBitmap((fieldWidth-imgWidth)/2, (fieldHeight-imgHeight-50)/2, 
      imgWidth, bitmap.getHeight(), bitmap , imgWidth*index, 0);  
    else 
     graphics.drawBitmap((fieldWidth-finalbitmap.getWidth())/2, (fieldHeight-finalbitmap.getHeight()-50)/2, 
      finalbitmap.getWidth(), finalbitmap.getHeight(), finalbitmap , 0, 0);  
} 

public int getPreferredWidth() 
{ 
     return fieldWidth; 
} 

public int getPreferredHeight() 
{ 
     return fieldHeight; 
} 

protected void layout(int arg0, int arg1) 
{ 
     setExtent(getPreferredWidth(), getPreferredHeight()); 
} 

public void startAnimation(){ 
    //System.out.println("startAnimation"); 
    animate=true; 
    thread = new Thread(this); 
    thread.start(); 
} 

public void updateLayout(int height, int width){ 
    //System.out.println("updateLayout:height:"+height); 
    this.fieldHeight=height; 
    this.fieldWidth=width; 
    super.updateLayout(); 
} 

public void stopAnimation(Bitmap bitmap){ 
    //System.out.println("stopAnimation");   
    this.finalbitmap=bitmap; 
    animate=false; 
}  

public void stopAnimation(){ 
    //System.out.println("stopAnimation"); 
    animate=false; 
}  

public void run(){ 
     while(animate){ 
      //System.out.println("run:animate:"+animate); 
      try{ Thread.sleep(interval);}catch(Exception e){} 
      if (index+1>=frameno) 
       index=0; 
      else 
       index++; 
      invalidate(); 
     } 
} 

}

appel de

: // chargement

Bitmap load_icon = Bitmap.getBitmapResource("loading.png"); 
    AnimatedImageField spinner = new AnimatedImageField(Display.getWidth(), Display.getHeight(), load_icon, 
      12, 100, Field.FIELD_HCENTER | Field.FOCUSABLE 
      | Field.FIELD_VCENTER); 
    spinner.startAnimation(); 
    add(spinner); 
+0

Cela ne fonctionne pas pour moi, je veux juste une image statique simple à afficher pendant que mon contenu Web est chargé . Aidez-moi, s'il vous plaît. –

Questions connexes