Blackberry -- Listfield with transparent rows
I have a screen with a background image being rendered like so:
bg = new VerticalFieldManager(
VerticalFieldManager.USE_ALL_WIDTH |
VerticalFieldManager.USE_ALL_HEIGHT |
VerticalFieldManager.NO_HORIZONTAL_SCROLLBAR |
VerticalFieldManager.NO_VERTICAL_SCROLLBAR |
VerticalFieldManager.NO_HORIZONTAL_SCROLL |
VerticalFieldManager.NO_VERTICAL_SCROLL) {
//Override the paint method to draw the background image.
public void paint(Graphics graphics) {
//Draw the background image and then call paint.
graphics.drawBitmap(Graphics.getScreenWidth()/2 - bgBitmap.getWidth()/2,
Graphics.getScreenHeight()/2 - bgBitmap.getHeight()/2,
bgBitmap.getWidth(), bgBitmap.getHeight(), bgBitmap, 0, 0);
super.paint(graphics);
}
};
add(bg);
Then I'm adding any fields for the screen to this manager. I have a ListField that I'd like to see the background through. When the screen is first rendered, all is well. I can see the image. As soon as I scroll down, select something and unselect it, the background disappears (turns white).
Do I need to do something special when drawing my list rows in order to make them truly transparent after the selection color is gone?
NOTE: I've found that this happens no matter what field is drawn on top of the background. It displays correctly until the selection color is drawn for a given focusable field and then you select something else. All the area that was filled with the selection color turns to the default white after unsel开发者_高级运维ecting it.
use invalidate() function within onfocus() and onunfocus() method.
For example if you use LabelField then use:
LabelField l=new LabelField("Hello",FOCUSABLE)
{
protected void onFocus(int direction)
{
invalidate();
super.onFocus(direction);
}
protected void onUnfocus()
{
invalidate();
super.onUnfocus();
}
};
I ended up overriding moveFocus() in my custom ListField.
public int moveFocus(int amount, int status, int time) {
invalidate(getSelectedIndex());
return super.moveFocus(amount, status, time);
}
Vivek's method works well for single fields outside of a ListField row though.
精彩评论