黑莓屏幕导航
问题描述:
我有一个屏幕名称下载屏幕当屏幕开始时它将开始下载一些文件,当下载完成后它会自动转到下一个屏幕。我使用下面的代码。黑莓屏幕导航
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());
}
});
}
}
该代码工作正常,并开始下载文件,当下载完成后,它将前进到下一个屏幕。但是当没有文件需要下载phraseList
数组长度为零时,它不会前进。我的代码中有什么问题?
答
的GuageField不喜欢从0到0。当长度为零,不添加GuageField。
答
更改代码以
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.
}