How to show images in the place of label in black berry screen using eclips plugin
I am developing one Blackberry application using Eclipse, I need to show images in the place of label like for e开发者_运维知识库xample new button is there in the place of new button i need to show some image. How can i show images can you please give one example.
Thanking you
try this
import net.rim.device.api.system.Bitmap;
import net.rim.device.api.ui.Field;
import net.rim.device.api.ui.Graphics;
public class CustomButton extends Field {
final Bitmap bitmap1;
final Bitmap bitmap2;
Bitmap bitmap;
CustomButton() {
bitmap1 = Bitmap.getBitmapResource("button_01.jpg");
bitmap2 = Bitmap.getBitmapResource("button_02.jpg");
bitmap = bitmap1;
}
public int getPreferredHeight() {
return bitmap1.getHeight();
}
public int getPreferredWidth() {
return bitmap1.getWidth();
}
protected void paint(Graphics g) {
g.drawBitmap(0, 0, getWidth(), getHeight(), bitmap, 0, 0);
}
protected void fieldChangeNotify(int context) {
try {
getChangeListener().fieldChanged(this, context);
} catch (Exception exception) {
}
}
public boolean isFocusable() {
return true;
}
protected void layout(int width, int height) {
setExtent(Math.min(width, getPreferredWidth()), Math.min(height,
getPreferredHeight()));
}
protected void onFocus(int direction) {
bitmap = bitmap2;
invalidate();
}
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(1);
return true;
}
protected void onUnfocus() {
bitmap = bitmap1;
invalidate();
}
}
and call like this
CustomButton button = new CustomButton(){
protected void fieldChangeNotify(int context) {
//button click
super.fieldChangeNotify(context);
}
};
精彩评论