我想创建一个自定义加载屏幕我创建了一个可以这样做但它不起作用的类
我创建了 LoadingScreen 类,它传递一组图像字符串以在加载时加载图像
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.container.MainScreen;
import net.rim.device.api.ui.container.VerticalFieldManager;
import net.rim.device.api.ui.decor.BackgroundFactory;
public class LoadingScreen extends MainScreen {
VerticalFieldManager vfm_Progress;
String progressImgStr[]={"progress0000.png","progress0001.png","progress0002.png","progress0003.png","progress0004.png","progress0005.png","progress0006.png","progress0007.png"};
public LoadingScreen() {
this.getMainManager().setBackground(BackgroundFactory.createSolidTransparentBackground(Color.BLACK, 200));
vfm_Progress=new VerticalFieldManager();
LoadThread spin=new LoadThread(progressImgStr,this);
spin.startLoading();
spin.start();
}
}
然后这个类调用一个线程类,它加载图像并附加到 LoadingScreen 的 VerticalFieldManager 但是......它不起作用,所以我得到一个名为 IIlegalStateException 的错误
Thread类如下
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.component.BitmapField;
public class LoadThread extends Thread{
private String[] mProgressImgStr;
private boolean isLoading=false;
LoadingScreen loadScreen;
public LoadThread(String[] progressImgStr,LoadingScreen loadScreen) {
this.mProgressImgStr=progressImgStr;
this.loadScreen=loadScreen;
}
public void run() {
if(isLoading)
{
for (int i = 0; i < mProgressImgStr.length; i++) {
Bitmap img=Bitmap.getBitmapResource(mProgressImgStr[i]);
BitmapField progressImgFld=new BitmapField(img);
loadScreen.vfm_Progress.add(progressImgFld);
loadScreen.add(loadScreen.vfm_Progress);
try {
this.sleep(250);
loadScreen.vfm_Progress.delete(progressImgFld);
loadScreen.delete(loadScreen.vfm_Progress);
} catch (InterruptedException e) {
e.printStackTrace();
}
if(i==mProgressImgStr.length-1)
{
i=0;
}
}
}
//super.run();
}
public void stopLoading()
{
isLoading=false;
}
public void startLoading()
{
isLoading=true;
}
}