Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Java Development

Reply
Highlighted
Regular Contributor
Posts: 55
Registered: ‎09-01-2010
My Device: Not Specified
Accepted Solution

BitmapField focus-unfocus prob

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?

Developer
Posts: 16,985
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport
My Carrier: O2 Germany

Re: BitmapField focus-unfocus prob

maybe the selectedLabel is not visible inside the bitmapfield?
is it a property of the screen?
----------------------------------------------------------
feel free to press the like button on the right side to thank the user that helped you.
please mark posts as solved if you found a solution.
@SimonHain on twitter
Developer
Posts: 263
Registered: ‎05-18-2011
My Device: Curve 9300, BB10 Dev Alpha C, Z10

Re: BitmapField focus-unfocus prob

What if you replace:

 public void setFocus(){
            super.setFocus();
            selectedLabel.setText("tab1");        
        }
        
        public void onUnfocus(){
            super.onUnfocus();
            selectedLabel.setText("");    
        }

with

 protected void onFocus(int direction)
            super.setFocus();
            selectedLabel.setText("tab1111");        
        }
        
        protected void onUnfocus()
            super.onUnfocus();
            selectedLabel.setText("tab2222");    
        }

 

--tom