Display sequence of words on BlackBerry screen
I have ten words in a string array. As an example: {"A B","C D","E F","G H"......}. I have to display these words in succession, holding each word on screen for 2 seconds. With each new word displayed, the font size needs to get smaller开发者_Go百科 as well.
How do I do this on a BlackBerry?
You can use a Timer
to control the timing:
import java.util.Timer
int index;
String[] words;
...
TimerTask task = new TimerTask() {
public void run()
{
// TODO: Check the bounds and kill the timer when we're done.
// Invoke the code in the UI Thread
UiApplication.getUiApplication().invokeLater(new Runnable() {
public void run()
{
// Code to enumerate and concat the string...
}
});
}
};
timer timer = new Timer();
timer.scheduleAtFixedRate(task, 0, 2000);
To change font size:
// in the class body:
final int minFontSize = 5;
int maxFontSize = minFontSize + words.length();
// in the timer's run method:
net.rim.device.api.ui.Font defaultFont = this.getFont();
net.rim.device.api.ui.Font myFont = defaultFont.derive(0, maxFontSize - index)
// change the font of the ui control
field.setFont(myFont);
I haven't checked the code to see if it compiles, but I hope you get the idea.
精彩评论