0

我正在黑莓 Java 开发中开发一个应用程序。我请求http意味着我正在连接到网络服务。网络服务的响应需要一些时间。那个时候我想显示一些等待屏幕。

你能告诉我我该怎么做吗......

问候 Pankaj Pareek

4

4 回答 4

1

它已经在这里:
Stackoverflow - Blackberry - 带有动画的加载屏幕
Stackoverflow - Blackberry - 应用程序加载屏幕

于 2009-12-28T14:33:53.213 回答
1

基本上你需要在后台线程中启动网络请求。一旦网络操作完成,您应该通知主/UI 线程将等待屏幕更改为结果。

要通知主线程,请查看下面的链接并搜索:http invokeLater:
//developers.sun.com/mobility/midp/articles/blackberrydev/

忠告:不要在移动设备上同时生成多个线程。通常它们的最大线程数非常低。

于 2009-12-28T11:55:02.717 回答
0

我创建了一个自定义动画位图字段,如下所示:

//线程类

public class AnimatedImageField  extends BitmapField implements Runnable
{  

private Thread thread = null;
private boolean animate=true;
private int interval = 0;
private int index=0;
private Bitmap bitmap = null;
private int frameno = 0;
private int fieldHeight=0;
private int fieldWidth=0;
private Bitmap finalbitmap = null;
private int imgHeight = 0;
private int imgWidth= 0;

public AnimatedImageField(int fieldwidth, int fieldheight, Bitmap bitmap, int frameno, int interval, long style)
{
    super(bitmap, style);
    this.interval=interval;
    this.bitmap=bitmap;
    this.frameno=frameno;
    imgHeight = bitmap.getHeight();
    int imgwidth = bitmap.getWidth();
    imgWidth=imgwidth/frameno;
    this.fieldWidth = fieldwidth;
    this.fieldHeight = fieldheight;
}

public AnimatedImageField(Bitmap bitmap, int frameno, int interval, long style)
{
    super(bitmap, style);
    this.interval=interval;
    this.bitmap=bitmap;
    this.frameno=frameno;
    imgHeight = bitmap.getHeight();
    int imgwidth = bitmap.getWidth();
    imgWidth=imgwidth/frameno;
    fieldWidth = imgWidth;
    fieldHeight = imgHeight;
}

protected void paint(Graphics graphics){
    graphics.setColor(Color.WHITE);
    graphics.fillRect(0,0,this.getPreferredWidth(), this.getPreferredHeight());

    //System.out.println("animate:"+animate);
    if ( animate )
        graphics.drawBitmap((fieldWidth-imgWidth)/2, (fieldHeight-imgHeight-50)/2, 
            imgWidth, bitmap.getHeight(), bitmap , imgWidth*index, 0);     
    else
        graphics.drawBitmap((fieldWidth-finalbitmap.getWidth())/2, (fieldHeight-finalbitmap.getHeight()-50)/2, 
            finalbitmap.getWidth(), finalbitmap.getHeight(), finalbitmap , 0, 0);     
}

public int getPreferredWidth()
{
        return fieldWidth;
}

public int getPreferredHeight()
{
        return fieldHeight;
}

protected void layout(int arg0, int arg1)
{
        setExtent(getPreferredWidth(), getPreferredHeight());
}

public void startAnimation(){
     //System.out.println("startAnimation");
    animate=true;
    thread = new Thread(this);
    thread.start();
}

public void updateLayout(int height, int width){
    //System.out.println("updateLayout:height:"+height);
    this.fieldHeight=height;
    this.fieldWidth=width;
    super.updateLayout();
}

public void stopAnimation(Bitmap bitmap){
    //System.out.println("stopAnimation");        
    this.finalbitmap=bitmap;
    animate=false;
}    

public void stopAnimation(){
    //System.out.println("stopAnimation");
    animate=false;
}    

public void run(){
        while(animate){ 
            //System.out.println("run:animate:"+animate);
            try{ Thread.sleep(interval);}catch(Exception e){}
            if ( index+1>=frameno )
                index=0;
            else
                index++;
            invalidate();
        }
}

}

调用自://正在加载

    Bitmap load_icon = Bitmap.getBitmapResource("loading.png");
    AnimatedImageField spinner = new AnimatedImageField(Display.getWidth(), Display.getHeight(), load_icon,
            12, 100, Field.FIELD_HCENTER | Field.FOCUSABLE
            | Field.FIELD_VCENTER);
    spinner.startAnimation();
    add(spinner); 
于 2012-07-09T09:25:57.363 回答
0

做一件事....在按钮的监听事件中写下这个。

         UiApplication.getUiApplication().invokeLater(new Runnable(){
            public void run(){
             Status.show("Please Wait....",b,3600);
             message.setText(test(theFile));
            }
         });
于 2009-12-29T07:45:50.267 回答