开发者

loading indication in the ui screen itself with out using seperate screen or popup

开发者 https://www.devze.com 2023-02-16 14:39 出处:网络
I want to display a lodaing screen when user requests some http connections.I got some good samples from stackoverflow and google,But all of them displays the loading screen using a seperate screen.I

I want to display a lodaing screen when user requests some http connections.I got some good samples from stackoverflow and google,But all of them displays the loading screen using a seperate screen.I want to show it in the same screen where user request for http Connection. If开发者_如何学编程 any one have idea please share it to me,Thanks in advance.


I usually use a GaugeField in the status section of a MainScreen. Set it using the setStatus(Field field) method.


If your developing for OS v6.0 then RIM has provided the api for progress indication http://docs.blackberry.com/en/developers/deliverables/17971/Indicate_activity_1210002_11.jsp

For below OS v6.0 below code might help u.i.e ProgressAnimationField it is a custom field which takes the bitmap spinner/loader img, its num frames and style.

import net.rim.device.api.system.*;
import net.rim.device.api.ui.*;

/**
 * Custom class for spinner animation
 */
public class ProgressAnimationField extends Field implements Runnable 
{
    private Bitmap _bitmap;
    private int _numFrames;
    private int _frameWidth;
    private int _frameHeight;

    private int _currentFrame;
    private int _timerID = -1;

    private Application _application;
    private boolean _visible;

    public ProgressAnimationField( Bitmap bitmap, int numFrames, long style ) 
    {
        super( style | Field.NON_FOCUSABLE );
        _bitmap = bitmap;
        _numFrames = numFrames;
        _frameWidth = _bitmap.getWidth() / _numFrames;
        _frameHeight = _bitmap.getHeight();

        _application = Application.getApplication();
    }

    public void run() 
    {
        if( _visible ) {
            invalidate();
        }
    }

    protected void layout( int width, int height ) 
    {
        setExtent( _frameWidth, _frameHeight );
    }

    protected void paint( Graphics g ) 
    {
        g.drawBitmap( 0, 0, _frameWidth, _frameHeight, _bitmap, _frameWidth * _currentFrame, 0 );
        _currentFrame++;
        if( _currentFrame >= _numFrames ) {
            _currentFrame = 0;
        }
    }

    protected void onDisplay() 
    {
        super.onDisplay();
        _visible = true;
        if( _timerID == -1 ) {
            _timerID = _application.invokeLater( this, 200, true ); 
        } 
    }

    protected void onUndisplay() 
    {
        super.onUndisplay();
        _visible = false;
        if( _timerID != -1 ) {
            _application.cancelInvokeLater( _timerID );
            _timerID = -1;
        }
    }
}
0

精彩评论

暂无评论...
验证码 换一张
取 消