I want to display progress indicator on screen when images loading from web. i'm used below code.,
Bitmap bitmap ;
BitmapField imageField ;
VerticalFieldManager vfm= new VerticalFieldManager();
ProgressAnimationField spinner =new ProgressAnimationField(Bitmap.getBitmapResource("spinner2.png"));
vfm.add(spinner);
new Thread(new Runnable()
{
public void run()
{
bitmap = new UrlToImage(Constants.ICON_URL+"_big.png"+suffix).getImage();
imageField = new BitmapField(bitmap);
vfm.delete(spinner)
vfm.add(imagefield);
}
}).start();
If i execute , it throws illegalStateException. Again i change to ui thead.,
B开发者_Go百科itmap bitmap ;
BitmapField imageField ;
VerticalFieldManager vfm = new VerticalFieldManager();
ProgressAnimationField spinner =new ProgressAnimationField(Bitmap.getBitmapResource("spinner2.png"));
vfm.add(spinner);
UiApplication.getUiApplication().invokeLater(new Runnable()
{
public void run()
{
bitmap = new UrlToImage(Constants.ICON_URL+"_big.png"+suffix).getImage();
imageField = new BitmapField(bitmap);
vfm.delete(spinner)
vfm.add(imagefield);
}
});
No error display. but the progressanimationfield not animated. What to change on my code for animate the progressAnimatedField. Pls give any idea..
I think the problem is that you are trying to do both UI and non-UI operations on the UI thread. So, your UrlToImage
is holding the UI thread hostage while it is retrieving data from the network, preventing all other UI operations (including re-painting your animated progress indicator). What about something like this:
Bitmap bitmap ;
BitmapField imageField ;
VerticalFieldManager vfm = new VerticalFieldManager();
ProgressAnimationField spinner =new ProgressAnimationField(Bitmap.getBitmapResource("spinner2.png"));
vfm.add(spinner);
new Thread(new Runnable()
{
public void run()
{
bitmap = new UrlToImage(Constants.ICON_URL+"_big.png"+suffix).getImage();
imageField = new BitmapField(bitmap);
UiApplication.getUiApplication().invokeLater(new Runnable()
public void run() {
vfm.delete(spinner);
vfm.add(imagefield);
}
});
}
});
I know this is already marked as answered, but I was thinking you should look at my post about this subject here
It should make all your application heartbeat problems go away.
精彩评论