I am trying to change the bitmap of a custom buttonfield on focus. I have 2 images, one in grey, the other in red, and I wish to swap them when the button is focused.
This code is making the buttons twitch to the right value for a fraction of a second, going from grey to red. When focused it is selcted, and generates an unwanted event. After changing, it goes right back to the original color and the simulator freezes.
Can anyone help us find whats wrong with this code?
My custom buttonField class:
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.system.Characters;
import net.rim.device.api.ui.Color;
import net.rim.device.api.ui.Graphics;
import net.rim.device.api.ui.component.BitmapField;
public class ImageNavbarButtonField extends BitmapField{
private Bitmap image;
private boolean isFocused;
public ImageNavbarButtonField(Bitmap image) {
super(image);
this.image = image;
}
public boolean isFocusable() {
return true;
}
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
protected boolean trackwheelClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
protected void drawFocus(Graphics graphics, boolean on){}
public void onFocus(){
setBitmap(ImageResizer.generateHitBitmap(image));
invalidate();
}
public void onUnfocus(){
//super.onUnfocus();
setBitmap(image);
invalidate();
}
protected void paint(Graphics graphics) {
super.paint(graphics);
}
protected boolean keyChar(char character, int status, int time) {
if(Characters.ENTER == character || Characters.SPACE == character) {
fieldChangeNotify(0);
return true;
}
return super.keyChar(character, status, time);
}
}
try this
imagebutton classs is given below-