2009-12-28 206 views
0

我正在開發黑莓Java開發中的一個應用程序。 我正在請求http意味着我正在連接到Web服務。Web服務的響應需要一些時間。那時候我想顯示一些等待的屏幕。黑莓 - 等待屏幕

你能告訴我,我怎麼能做到這一點....

問候 潘卡Pareek

+0

我剛剛找到一些帖子這可能對你有用(如果你還沒有看到它們)。 http://www.blackberryforums.com/developer-forum/63182-simple-please-wait-screen.html – Alex 2009-12-28 11:55:55

回答

1

基本上你需要開始在後臺線程的網絡請求。 網絡操作完成後,您應通知主/ UI線程將等待屏幕更改爲結果。

要通知主線程看看下面的鏈接,搜索invokeLater:建議
http://developers.sun.com/mobility/midp/articles/blackberrydev/

字:一次不衍生到多個線程在移動設備上。通常它們的線程的最大數量非常低。

0

做一件事.... 在按鈕的讀心人事件中寫入這一點。

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

我創建一個自定義動畫位圖字段,就像這樣:// 裝載

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); 

//線程類

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(); 
     } 
} 

}

從通話

+0

這不適合我,我只想要一個簡單的靜態圖像顯示,而我的網頁內容正在加載。請幫助。 – 2013-02-25 11:42:22