Bohemian
Bohemian

Reputation: 6067

Blackberry - how to animate Custom Field?

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.

Upvotes: 1

Views: 884

Answers (1)

Marc Novakowski
Marc Novakowski

Reputation: 45398

Try calling invalidate() in your setValue method.

Upvotes: 3

Related Questions