2012-03-30 7 views
0

화면 이름이 DownloaderScreen 화면이 시작되면 파일 다운로드가 시작되고 다운로드가 완료되면 자동으로 다음 화면으로 넘어갑니다. 다음 코드를 사용합니다.검은 딸기 화면 탐색

public DownloaderScreen() { 
     super(NO_VERTICAL_SCROLL | NO_HORIZONTAL_SCROLL | USE_ALL_HEIGHT 
       | USE_ALL_WIDTH); 

     this.application = UiApplication.getUiApplication(); 
     HorizontalFieldManager outerBlock = new HorizontalFieldManager(USE_ALL_HEIGHT); 
     VerticalFieldManager innerBlock = new VerticalFieldManager(USE_ALL_WIDTH | FIELD_VCENTER); 
     innerBlock.setPadding(0, 10, 0, 10); 
     outerBlock.setBackground(BackgroundFactory 
       .createBitmapBackground(LangValue.dlBgimg)); 
     outerBlock.add(innerBlock); 
     add(outerBlock); 

     phraseHelper = new PhraseHelper(); 
     final String[][] phraseList = phraseHelper.getDownloadList(); 

     gaugeField = new GaugeField("Downloading ", 0, phraseList.length, 0, GaugeField.PERCENT); 
     innerBlock.add(gaugeField); 

     Thread dlTread = new Thread() { 
      public void run() { 
       startDownload(phraseList); 
      } 
     }; 
     dlTread.start(); 

    } 

private void startDownload(String[][] phraseList){ 

     if(phraseList.length!=0){ 

      for(int i=0; i < phraseList.length ; i++){// 
       gaugeField.setValue(i); 
       // code for download 
      } 
     } 
     goToNext(); 
    } 

private void goToNext() { 

final Screen currentScreen = application.getActiveScreen(); 

    if (UiApplication.isEventDispatchThread()) { 
     application.popScreen(currentScreen); 
     application.pushScreen(new HomeScreen()); 
     } else { 
      application.invokeLater(new Runnable() { 
       public void run() { 
        application.popScreen(currentScreen); 
        application.pushScreen(new HomeScreen()); 
       } 
      }); 
     } 
} 

코드가 정상적으로 작동하고 파일 다운로드가 시작되며 다운로드가 완료되면 다음 화면으로 넘어갑니다. 그러나 다운로드 할 파일이 없을 때 배열 길이가 0 인 경우 phraseList은 앞으로 진행되지 않습니다. 내 코드의 문제점은 무엇입니까?

답변

1

의 코드는, GuageField를 추가하지 마십시오.

1

변경 길이가 제로 일 때 GuageField 0으로 0에서가는 좋아하지 않는

if(phraseList.length!=0){ 

     for(int i=0; i < phraseList.length ; i++){// 
      gaugeField.setValue(i); 
      // code for download 
     } 
     goToNext(); 

    } 
    else{ 
     goToNext(); //if nothing to download, then it will goto the next screen. 
     } 
관련 문제