2011-10-14 21 views
0

我想在黑莓中實現一個加載屏幕。我用下面的代碼加載屏幕在Blackberry中不起作用?

PleaseWaitPopupScreen.showScreenAndWait(new Runnable() { 

     public void run() { 
          //**Segment 1** here i write the code for network call 
            } 
          }, "please wait"); 
        // **Segment 2**:Here processing the data get from network call 

問題段完成1段2名之前的作品我也嘗試下面的代碼

HorizontalFieldManager popHF = new HorizontalFieldManager(); 
    popHF.add(new LabelField("Pls wait...")); 
    final PopupScreen waitScreen = new PopupScreen(popHF); 
    new Thread() 
    { 
     public void run() 
     { 

      synchronized (UiApplication.getEventLock()) 
      { 
       UiApplication.getUiApplication().pushScreen(waitScreen); 
      } 
      // **Segment 1**Here Some Network Call 

      synchronized (UiApplication.getEventLock()) 
      { 
       UiApplication.getUiApplication().popScreen(waitScreen); 

      } 
     } 
    }.start(); 
    // **Segment 2**:Here processing the data get from network call 

出現同樣問題嘗試從以下Support forum link代碼。任何幫助將不勝感激。

感謝

回答

1

其實這取決於你在段2做的事情如果沒有UI操作,然後只要將2段,使HTTP調用線程內。例如: -

final PopupScreen waitScreen = new PopupScreen(popHF); 
new Thread() 
{ 
    public void run() 
    { 
     synchronized (UiApplication.getEventLock()) 
     { 
      UiApplication.getUiApplication().pushScreen(waitScreen); 
     } 
     // **Segment 1**Here Some Network Call 

     // **Segment 2**:Here processing the data get from network call 

     synchronized (UiApplication.getEventLock()) 
     { 
      UiApplication.getUiApplication().popScreen(waitScreen); 
     } 
    } 
}.start(); 

但如果有段2的內部UI操作,然後調用它的UI線程,你取出後馬上等待屏幕:

final PopupScreen waitScreen = new PopupScreen(popHF); 
new Thread() 
{ 
    public void run() 
    { 
     synchronized (UiApplication.getEventLock()) 
     { 
      UiApplication.getUiApplication().pushScreen(waitScreen); 
     } 
     // **Segment 1**Here Some Network Call 

     synchronized (UiApplication.getEventLock()) 
     { 
      UiApplication.getUiApplication().popScreen(waitScreen); 
      // **Segment 2**:Here processing the data get from network call 
     } 
    } 
}.start(); 
+0

大。這工作正常。我想添加ui組件。所以我使用第二種方法。 –