开发者

Delay displaying of fields in manager (blackberry)

I have a loop adding fields to a manager, I am trying to delay the time between when each field is painted onto the screen. I have been trying below code but it just paints the manager when all fields have bee开发者_StackOverflow中文版n added to it. Is this possible ?

manager.add(field);
manager.invalidate();//force a repaint of the manager
Thread.sleep(1000);

Thanks


Invalidate doesn't necessarily force a paint, it simply says that on the next paint the Field (or Manager in your case) needs to be redrawn. It's a subtle difference but it could be causing the confusion. What you might want to try is calling Screen.doPaint(), which will force the entire screen to redraw. Also, putting the sleep() in your Event Thread won't help, because painting is also done on the same Thread.

If you are trying to sequentially add Fields to your Manager with this second delay, you should put this logic in its own Thread and do synchronized(UiApplication.getEventLock()){//add fields} when you call manager.add(field). Then you can call your Thread.sleep(1000) to correctly have the delay in displaying. Also, just as a some added info, calling add() inherently causes an invalidate() call, so you don't need to add it. Here's a simple example of the second delay in adding

protected void addDelayedFields() {
    Thread t = new Thread( new Runnable() {
        public void run() {
            for(int i=0;i<SOME_LIMIT;i++) {
                synchronized(UiApplication.getEventLock()) {
                    manager.add(new LabelField(i.toString());
                }
                try{
                    Thread.sleep(1000);
                }
                catch(Exception e){ }
            }
        }
    });
    t.start();
}

The painting should occur after the add(), but if it doesn't you can also make a call to yourScreen.doPaint()

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜