加载屏幕
问题描述:
返回数据从该页面加载屏幕
BlackBerry Please Wait Screen with Time out
这是工作顺利实施loading画面时,我有一个问题,但问题是我无法从该代码得到字符串数据。
这个想法是我想从webservice捕获json数据时加载屏幕,并将其作为字符串返回。但是我因为下面的代码无法返回数据而卡住了。
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(thisScreen)
有什么建议吗?
答
您可以使用Interface
来实现。当您调用方法PleaseWaitPopupScreen.showScreenAndWait(Runnable, String)
(来自链接BlackBerry Please Wait Screen with Time out)时,可以在该方法上添加另一个参数。如果将一个接口实例用作第三个参数,则可以使用该接口的回叫方法来通知关闭事件PopupScreen
。您可以尝试以下程序。
创建一个接口,定义回调方法。
interface PopupScreenCloseListener {
// Invoke this method when PopupScreen gets closed.
public void popupScreenClosed();
}
实现接口和附加它作为showScreenAndWait
第三个参数。还可以通过回调方法获取PopupScreen关闭事件通知。
class MyClass implements PopupScreenCloseListener {
public void showWaitingPopupScreen(final Runnable runThis, String text) {
// append the interface, PopupScreenCloseListener as third parameter
PleaseWaitPopupScreen.showScreenAndWait(runThis, text, this);
}
public void popupScreenClosed() {
// listen PopupScreen close event here...
// and add codes...
}
}
并修改目前实施的方法,showScreenAndWait
。
public static void showScreenAndWait(final Runnable runThis, String text, final PopupScreenCloseListener listener) {
// old codes...
// old codes...
// Now dismiss this screen
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run() {
UiApplication.getUiApplication().popScreen(thisScreen);
// notify PopupScreen close event.
if (listener != null) {
listener.popupScreenClosed();
}
}
});
// old codes...
// old codes...
}