BitmapField click does not work on Blackberry application
i arranged 7 bimapfield in horizontal if i click the bitmapfield it want to push the another screen Here is my code but i did't get the another screen can any one help me whats wrong in this code
BitmapField bitmap1 = new BitmapField(
Bitmap.getBitmapResource("profile_n.png"),FOCUSABLE | DrawStyle.HCENTER)
{
protected void onFocus(int direction)
{
rollno=1开发者_运维技巧;
this.getScreen().invalidate();
}
protected void onUnfocus()
{
}
protected boolean navigationClick(int status, int time){
UiApplication.getUiApplication().popScreen(getScreen());
UiApplication.getUiApplication().pushScreen(new AccMainScreen());
return true;
}
};
You can use a custom field that hold a image and behave like a button instead of bitmapfield. Here is the code i suggest:
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{
protected Bitmap icon;
protected int fieldWidth;
protected int fieldHeight;
public CustomButton (String iconSource,long style) {
super(style);
icon = Bitmap.getBitmapResource(iconSource);
fieldHeight = icon.getHeight();
fieldWidth = icon.getWidth();
}
public int getPreferredWidth() {
return fieldWidth;
}
public int getPreferredHeight() {
return fieldHeight;
}
protected void layout(int arg0, int arg1) {
setExtent(getPreferredWidth(), getPreferredHeight());
}
protected void drawFocus(Graphics graphics, boolean on){ }
protected void paint(Graphics graphics) {
graphics.fillRect(0, 0, fieldWidth, fieldHeight);
graphics.drawBitmap(0,0, fieldWidth, fieldHeight, icon, 0, 0);
}
protected boolean navigationClick(int status, int time) {
fieldChangeNotify(0);
return true;
}
}
you can use this button like a default button and change listener of it by using setChangeListener function.
CustomButton aButton = new CustomButton ("graphics/someIcon.png");
aButton.setChangeListener(new FieldChangeListener() {
public void fieldChanged(Field field, int context) {
UiApplication.getUiApplication().popScreen(getScreen());
UiApplication.getUiApplication().pushScreen(new AccMainScreen());
}
});
精彩评论