我正在开发黑莓java开发中的一个应用程序。 我请求http意味着我连接到Web服务。响应Web服务需要一些时间。那时我想显示一些等待屏幕。
你能告诉我我该怎么做......
此致 Pankaj Pareek
答案 0 :(得分:1)
基本上,您需要在后台线程中启动网络请求。 网络操作完成后,您应该通知主/ UI线程将等待屏幕更改为结果。
要通知主线程,请查看下面的链接并搜索invokeLater
:
http://developers.sun.com/mobility/midp/articles/blackberrydev/
建议:不要在移动设备上同时产生多个线程。通常它们的最大线程数非常少。
答案 1 :(得分:1)
它已经在这里:
Stackoverflow - Blackberry - Loading screen with animation
Stackoverflow - Blackberry - Application loading screen
答案 2 :(得分:0)
做一件事...... 在按钮的监听器事件中写下这个。
UiApplication.getUiApplication().invokeLater(new Runnable(){
public void run(){
Status.show("Please Wait....",b,3600);
message.setText(test(theFile));
}
});
答案 3 :(得分: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);