I want to set a text in a specific label on focus of an BitmapField, and reset the text on unfocus. I am using the following code:
final BitmapField tab1 = new BitmapField(Bitmap.getBitmapResource("img/icon1.png"), FIELD_BOTTOM | BitmapField.FOCUSABLE) {
protected void drawFocus(Graphics graphics, boolean on) {
// the simplies way to draw a rectangle and this will be the
// focus
}
protected boolean navigationClick(int status, int time) {
// write here your code what you want to run the user clicks to
// the bitmap
// try something like this
Dialog.alert("Code for tab1");
return true;
}
public void setFocus(){
super.setFocus();
selectedLabel.setText("tab1");
}
public void onUnfocus(){
super.onUnfocus();
selectedLabel.setText("");
}
};
But focus is changing properly, but label is not setting at all. Where is the problem in my code?
override onFocus(int direction) instead of setFocus()
protected void onFocus(int direction) {
super.onFocus(direction);
selectedLabel.setText("tab1");
}
protected void onUnfocus() {
super.onUnfocus();
selectedLabel.setText("");
}
Use onfocus() & onUnfocus() method and replace your LabelField in both method with Invalidate() option .
Related
I want to remove the black background in Popup field
i know we use applyTheme method in blackberry to subdue its effect but dunno how to use it
I want to remove the black background and use an image instead .
I have tried this method
protected void applyTheme(Graphics arg0, boolean arg1) {
// TODO Auto-generated method stub
super.applyTheme(arg0, arg1);
}
public class CustomDialogBox extends PopupScreen {
Bitmap mDialogImg=null;
public CustomDialogBox(Bitmap dialogImg) {
super(new VerticalFieldManager(),Field.FOCUSABLE);
this.mDialogImg=dialogImg;
VerticalFieldManager vfm=new VerticalFieldManager() {
protected void paint(Graphics graphics) {
graphics.drawBitmap(0, 0, mDialogImg.getWidth(), mDialogImg.getHeight(), mDialogImg, 0, 0);
};
protected void sublayout(int maxWidth, int maxHeight) {
super.sublayout(mDialogImg.getWidth(), mDialogImg.getHeight());
super.setExtent(mDialogImg.getWidth(), mDialogImg.getHeight());
}
};
add(vfm);
}
protected void applyTheme() {
}
}
I tried the following program and it works perfectly fine
i added a Bitmap image to a vertical field manager and then
using the method
applyTheme() as follows
protected void applyTheme() {
}
i do get the required results
I want to hilight the background of a horizontalFieldManager when I'm scrolling. I tried this code:
public class HorizentalFocus extends HorizontalFieldManager{
protected void paint(Graphics g) {
g.setBackgroundColor(isFocus() ? 4210231 : 0xFFFFFF);
g.getFont();
g.clear();
super.paint(g);
}
protected void onFocus(int direction) {
invalidate();
super.onFocus(direction);
}
protected void onUnfocus() {
invalidate();
super.onUnfocus();
}
}
It works but I have two problems: it doesn't hilight the entire horizontalField and I want to change the color of the text when it's focused.
Thanks for your help.
I am preparing for a new app, just want to create a TextField.
I have to provide functionality to select a portion of text and change its color.
For example: hello, I am blackberry developer.
Now I want to change the font color of blackberry developer at runtime.
Is it possible in EditField or BasicEditField or RichTextField in any one???
Thanxx in advance!:)
LabelField labelField2 = new LabelField("hello, I am blackberry developer",Field.FOCUSABLE){
boolean _inFocus = false;
public void onFocus(int direction) {
_inFocus = true;
this.invalidate();
}
public void onUnfocus() {
_inFocus = false;
this.invalidate();
}
protected void paint(Graphics graphics) {
if(_inFocus){
graphics.setColor(Color.BLUE);
}else{
graphics.setColor(Color.RED);
}
super.paint(graphics);
}
protected void drawFocus(Graphics g, boolean on) {
}
};
Enjoy...
Currently I have 4 bitmap buttons in my application. I want to have something like Label/Name for each of the buttons so that whenever someone focus on the particular button, the name appears somewhere on the screen. It could be on top, below the buttons or anywhere will do.
How can I do this? I tried searching for bitmap button field labelling but I found nothing really helpful.
you can put a CustomLabelField below button fields. Override your ButtonFields onFocus(int direction) and onUnfocus() methods. Inside them invoke setLabel(String label) method of your CustomLabelField
class CustomLabelField extends Field {
String label;
public void setLabel(String label){
this.label = label;
invalidate();
}
protected void layout(int arg0, int arg1) {
setExtent(Display.getWidth, getFont().getHeight());
}
protected void paint(Graphics graphics) {
graphics.setColor(Color.Black);
graphics.drawText(label, 0, 0);
}
}
EDIT (after comments)
You can use this custom button and add your additional features in it. I did not try if this is working, but should work.
import net.rim.device.api.ui.component.BitmapField;
import net.rim.device.api.ui.container.MainScreen;
public class CustomButtonField extends BitmapField{
private String label = "";
private MainScreen yourScreen;
public CustomButtonField(String label, MainScreen yourScreen) {
super();
this.label = label;
this.yourScreen = yourScreen;
}
protected void onFocus(int direction) {
yourScreen.setTitle(label);
super.onFocus(direction);
}
protected void onUnfocus() {
yourScreen.setTitle("");
super.onUnfocus();
}
}
How to place bitmapFields in Manager while some buttons on it get focus.I tried following code but it is not working.`
when "button" get focus I need to add "field1" beside the button in Vfm.
button = new ImgButtonField("res/images/trans.png", Field.FOCUSABLE){
protected void onFocus(int direction) {
Vfm.insert(field1, button.getIndex()) ;
super.onFocus(direction);
invalidate();
}
protected void onUnfocus() {
Vfm.delete(field1);
super.onUnfocus();
invalidate();
}
};
Try using add rather than insert ,sample code i tried
ButtonField button,button1;
LabelField field1;
VerticalFieldManager vfm;
public MyScreen()
{
// Set the displayed title of the screen
setTitle("MyTitle");
vfm=new VerticalFieldManager();
field1=new LabelField("Sample");
button=new ButtonField("Sample"){
protected void onFocus(int direction) {
vfm.add(field1);
super.onFocus(direction);
invalidate();
}
protected void onUnfocus() {
vfm.delete(field1);
super.onUnfocus();
invalidate();
}
};
button1=new ButtonField("Sampl1");
this.add(button1);
this.add(button);
this.add(vfm);
}
Regards
Rakesh Shankar.P
Try placing a NullField in the manager as a placeholder. The NullField will not be visible. On focus, you can replace that NullField with field1.
NullField myNullField = new NullField();
button = new ImgButtonField("res/images/trans.png", Field.FOCUSABLE){
protected void onFocus(int direction) {
Vfm.replace(myNullField, field1) ;
super.onFocus(direction);
invalidate();
}
protected void onUnfocus() {
Vfm.replace(field1, myNullField);
super.onUnfocus();
invalidate();
}
};
//add fields to Vfm, including the myNullField placeholder.