код ниже может дать вам более глубокое понимание тикера. Просто создайте объект для класса ниже и передайте необходимые аргументы.Это сделало бы вашу работу.Я думаю :)
import java.util.Timer;
import java.util.TimerTask;
import net.rim.device.api.system.Display;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Font;
import net.rim.device.api.ui.Graphics;
public class TickerField extends Field {
String text;
static final int screenWidth = Display.getWidth();
int offset;
private Timer timer = new Timer();
final int delay = 30;
private static int fontH = Font.getDefault().getHeight();
private int w;
private int h;
private int bgColor = Color.WHITE;
public TickerField(String text, int width, int height) {
this.text = text;
w = width;
h = height;
offset = w;
final int textWidth = Font.getDefault().getAdvance(text);
//schedule and start timertask
TimerTask timerTask = new TimerTask() {
public void run() {
offset--;
if (offset + textWidth == 0) {
offset = screenWidth;
}
invalidate();
}
};
timer.scheduleAtFixedRate(timerTask, delay, delay);
}
public TickerField(String text) {
this(text, screenWidth, fontH);
}
public TickerField(int width, int height) {
this("", width, height);
}
public TickerField() {
this("", screenWidth, fontH);
}
//set ticker text
public void setText(String text) {
this.text = text;
}
//get ticker text
public String getText() {
return text;
}
// implement layout to give specific arrangement to this field
// Invoke Math.min() to return the smaller of the user specified w and h,
// and the preferred width and height of the field.
protected void layout(int width, int height) {
width = Math.min(w, getPreferredWidth());
height = Math.min(h, getPreferredHeight());
setExtent(width, height);
}
// Implement the paint() to redraw the field with different
// offset controlled by timer task.That will give the
// ticker effect.
protected void paint(Graphics graphics) {
graphics.drawText(text, offset, 0);
}
public void setBgColor(int bgColor) {
this.bgColor = bgColor;
}
//Implement the paintBackground() method to change the
//background color of the field.
protected void paintBackground(Graphics g) {
g.setBackgroundColor(bgColor);
g.clear();
super.paintBackground(g);
}
// Implement getPreferredWidth() and getPreferredHeight(), using the
// screenWidth and font height to make sure that the ticker does not exceed
// the dimensions of the
// component.
public int getPreferredWidth() {
return screenWidth;
}
public int getPreferredHeight() {
return fontH;
}
}
Happy Coding:)