I'm rather new to programming Blackberries and was wondering if anybody knows of a tutorial or a snippet about how to load an image into the screen and set an onClick listener to it?
edit, got this far:
ButtonField btf1 = new ButtonField("Fine!");
ButtonField btf2 = new ButtonField("Great!");
RichTextField rtf = new RichTextField("HELLO, HOW ARE YOU?");
Bitmap LOGO = Bitmap.getBitmapResource("1.png");
BitmapField LogoBmpField = new BitmapField(LOGO);
HelloWorldScreen()
{
setTitle("My First App");
add(rtf);
add(btf1);
add(btf2);
add(LogoBmpField);
}
Thanks!
edit: by the way, how should interfaces be ma开发者_如何学Pythonde for blackberry? simply by
ButtonField btf1 = new ButtonField("Fine!");
add(btf1);
Or is there some more visible way, such as in XML for android?
One more thing, how to I change or set properties of some object. Say I want to change the title of my button- btf1.(expecting list of available properties to appear ) doesn't give anything.
Place your image in your res folder and try this;
Bitmap bmpLogo = Bitmap.getBitmapResource("yourImage.jpg");
BitmapField logo = new BitmapField(bmpLogo){
protected boolean trackwheelClick(int status, int time)
{
// Your onclick code here
return true;
}
};
add(logo);
1) You need to make your BitmapField
focusable.
I just tried this:
BitmapField LogoBmpField = new BitmapField(LOGO, BitmapField.FOCUSABLE) {
protected boolean trackwheelClick(int status, int time) {
System.out.println(" -- You clicked me! ");
return true;
}
};
and it seems to work.
2) And to change the text on your button use setLabel()
btf1.setLabel("new button text");
public class MyScreen extends MainScreen {
public LanguageSelector() {
Bitmap logoBitmap = Bitmap.getBitmapResource("normalarabflag.png");
BitmapField LogoBmpField = new BitmapField(logoBitmap, BitmapField.FOCUSABLE | Field.FIELD_HCENTER) {
protected boolean navigationClick(int status, int time) {
System.out.println(" -- You clicked me! ");
UiApplication.getUiApplication().pushScreen(new SecoundScreen());
Dialog.alert("Load Complete");
return true;
}
};
LabelField labelfield = new LabelField("Arabic ",Field.FIELD_HCENTER|LabelField.FOCUSABLE);
VerticalFieldManager vrt=new VerticalFieldManager(USE_ALL_WIDTH) {
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(Display.getWidth(),Display.getHeight());
setExtent(Display.getWidth(),Display.getHeight());
}
};
Font f=labelfield.getFont();
int hight1=f.getAdvance(labelfield.getText());
int k=labelfield.getPreferredHeight();
int number=hight1/Display.getWidth()+1;
int hight2=logoBitmap.getHeight();
int padding=(Display.getHeight()-((number*k)+hight2))/2;
if(padding>0) {
LogoBmpField.setPadding(padding,0,0,0);
}
vrt.add(LogoBmpField);
vrt.add(labelfield);
add(vrt);
}
}
精彩评论