gpt4 book ai didi

user-interface - Blackberry - 应用程序加载屏幕

转载 作者:行者123 更新时间:2023-12-02 06:45:07 26 4
gpt4 key购买 nike

我的应用程序包含大量图像。所以加载应用程序需要一些时间。我想在加载应用程序时显示一个加载屏幕。怎么可能?

最佳答案

这是一个示例应用程序,它可以勾勒出您想要做什么。基本上,您推送的初始屏幕是加载屏幕。在初始启动序列中,您需要启动一个新线程,执行加载操作,然后使用 invokeLater 来 1) 确保您在事件调度程序中,以及 2) 推送一个新屏幕——或者在本例中dialog -- 到屏幕让用户离开加载屏幕。

代码如下:

import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.UiApplication;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.component.Dialog;
import net.rim.device.api.ui.component.LabelField;

/**
* Just a test app.
*/
public class TestAppMain extends UiApplication
{
/**
* Default Constructor.
*/
private TestAppMain() {
pushScreen(new AppScreen(this));
}

/**
* App entry point.
* @param args Arguments.
*/
public static void main(String[] args) {
TestAppMain app = new TestAppMain();
app.enterEventDispatcher();
}

/**
* Main application screen.
*/
private static class AppScreen extends MainScreen
{
UiApplication _app;

/**
* Default constructor.
*/
public AppScreen(UiApplication app) {
// Note: This screen just says "Loading...", but you could
// add a loading animation.
_app = app;
LabelField title = new LabelField("App Name",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);
setTitle(title);

LabelField loading = new LabelField("Loading...",
LabelField.ELLIPSIS | LabelField.USE_ALL_WIDTH);

add(loading);

// Queue up the loading process.
startLoading();
}

/**
* Create the loading thread. Make sure to invoke later as you will
* need to push a screen or show a dialog after the loading is complete, eventhough
* you are creating the thread before the app is in the event dispatcher.
*/
public void startLoading() {
Thread loadThread = new Thread() {
public void run() {
// Make sure to invokeLater to avoid problems with the event thread.
try{
// Simulate loading time
Thread.sleep(5000);
} catch(java.lang.InterruptedException e){}

// TODO - Add loading logic here.

_app.invokeLater( new Runnable() {
public void run() {
// This represents the next step after loading. This just shows
// a dialog, but you could push the applications main menu screen.
Dialog.alert("Load Complete");
}
});
}
};
loadThread.start();
}
}
}

关于user-interface - Blackberry - 应用程序加载屏幕,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1503313/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com