Blackberry - how to animate Custom Field?

柔情痞子 提交于 2019-12-03 22:36:26

问题


I have created a custom field class "Seek" to draw a fillrectangle.

class Seek extends Field {
    int fill;
    protected void layout(int width, int height) {
        setExtent(320, 5);
    }
    protected void paint(Graphics graphics) {
        graphics.setColor(Color.RED);
        graphics.fillRect(0, 0, fill, 5);
    }
    protected void setValue(int value) {
        fill = value;
    }
}

And I have created another class Test seek to set the fill value using a timer

public class TestSeek extends UiApplication {
    public static void main(String[] args) {
        TestSeek gbResults = new TestSeek();
        gbResults.enterEventDispatcher();
    }
    private TestSeek() {
        pushScreen(new ProgressScreen());
    }
}

class ProgressScreen extends MainScreen {
    Timer timer = new Timer();
    int i = 80;
    Seek SeekField = new Seek();

    public ProgressScreen() {
        add(SeekField);
        timer.schedule(new RemindTask(), 100, 10);
    }

    class RemindTask extends TimerTask {
        public void run() {
            if (i < 320) {
                i += 1;
                SeekField.setValue(i);
            } else
                timer.cancel();
        }
    }
}

But I am unable to animate filling the rectangle.


回答1:


Try calling invalidate() in your setValue method.



来源:https://stackoverflow.com/questions/1761185/blackberry-how-to-animate-custom-field

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!