私のアプリケーションにはたくさんの画像が含まれています。そのため、アプリケーションのロードに時間がかかります。アプリケーションのロード中にロード画面を表示したい。どのように可能ですか?
質問する
9956 次
2 に答える
8
これは、あなたがやりたいことを骨組みにするアプリの例です。基本的に、最初に押す画面はロード画面です。最初の起動シーケンス中に、新しいスレッドをスピンアップし、ロード作業を行ってから、invokeLater を使用して、1) イベント ディスパッチャで確認し、2) 新しい画面をプッシュする必要があります。この例の場合は、ダイアログ -- ユーザーがロード画面から離れるように画面に移動します。
コードは次のとおりです。
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();
}
}
}
于 2009-10-01T12:53:12.450 に答える
1
HorizontalFieldManager popHF = new HorizontalFieldManager();
popHF.add(new CustomLabelField("Pls wait..."));
final PopupScreen waitScreen = new PopupScreen(popHF);
new Thread()
{
public void run()
{
synchronized (UiApplication.getEventLock())
{
UiApplication.getUiApplication().pushScreen(waitScreen);
}
//Here Some Network Call
synchronized (UiApplication.getEventLock())
{
UiApplication.getUiApplication().popScreen(waitScreen);
}
}
}.start();
于 2011-09-27T06:47:55.697 に答える