我使用下面的代碼創建請稍候彈出的黑莓application.I想刪除彈出屏幕上回壓裝置的但我不能夠在這樣做,因爲 顯示的時候請等待彈出整個屏幕,直到線程運行完成。刪除,請等待彈出屏幕上的返回鍵
這裏是我的代碼:
public class PleaseWaitLoginPopupScreen extends PopupScreen {
//statics ------------------------------------------------------------------
private AnimatedGIFField _ourAnimation = null;
private LabelField _ourLabelField = null;
private static String pleaseWaitText="";
private static PleaseWaitLoginPopupScreen ref;
public static PleaseWaitLoginPopupScreen getInstance(){
if(ref!=null){
ref=new PleaseWaitLoginPopupScreen(Constant.PLEASE_WAIT_TEXT);
}
return ref;
}
public PleaseWaitLoginPopupScreen(String text) {
super(new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL | VerticalFieldManager.VERTICAL_SCROLLBAR));
GIFEncodedImage ourAnimation = (GIFEncodedImage) GIFEncodedImage.getEncodedImageResource("loader.gif");
_ourAnimation = new AnimatedGIFField(ourAnimation, Field.FIELD_HCENTER);
this.add(_ourAnimation);
_ourLabelField = new LabelField(text, Field.FIELD_HCENTER);
this.add(_ourLabelField);
}
public static void showScreenAndWait(final Runnable runThis, String text) {
pleaseWaitText=text;
final PleaseWaitLoginPopupScreen thisScreen = new PleaseWaitLoginPopupScreen(text);
Thread threadToRun = new Thread() {
public void run() {
// First, display this screen
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().pushScreen(thisScreen);
}
});
boolean exceptionFlag = false;
// Now run the code that must be executed in the Background
try {
runThis.run();
} catch (Throwable t) {
exceptionFlag = true;
t.printStackTrace();
//throw new RuntimeException("Exception detected while waiting: " + t.toString());
}finally{
// Now dismiss this screen
if(exceptionFlag){//IF EXCEPTION OCURES THAN THIS CODE WILL RUN TO STOP THE PLEASE WAIT POP TASK
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(thisScreen);
}
});
}
}
}
};
threadToRun.start();
}
public void dismissPopupScreen(){
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(PleaseWaitLoginPopupScreen.this);
}
});
/*synchronized (UiApplication.getEventLock()) {
UiApplication.getUiApplication().popScreen(PleaseWaitLoginPopupScreen.this);
}*/
}
}
什麼是代碼中的AnimatedGIFField。 – Mayank 2014-12-18 05:30:33