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
Developer
Posts: 103
Registered: ‎12-12-2011
My Device: Developer
My Carrier: Robosoft

Focus to BitmapField

Hello all,

 

I have a custom HorizontalFieldManager, in which I am adding a bitmap and an EditField and positioning the edit field as required. The edit field behaves absolutely fine until text is entered into it. I have also placed a BitmapField below the edit field, which would be clicked after the text is entered in edit field.

The problem I am facing is, after entering the text in edit field, the focus from edit field is moved to the BitmapField only if we press enter key in virtual keyboard. I am facing this problem only in OS 5.0 fully touch device and not in non-touch device. Any help would be greatly appreciated.

Thanks in advance.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Focus to BitmapField

You say you have a custom HFM, but you also say that the Bitmap is 'below' the EditField.  This is potentially confusing for a HFM, since it expects things laid out Horizontally.  I suggest you change your HFM to be just a Manager, and then I think you will find the Manager makes no assumptions about the positioning of Fields and it will therefore find all the Fields correctly. 

Developer
Posts: 103
Registered: ‎12-12-2011
My Device: Developer
My Carrier: Robosoft

Re: Focus to BitmapField

Hello Peter,

 

Sorry for not being clear in the description, I have taken a custom HFM since I wanted to have an edit field with an image(bitmap). But I am placing this custom HFM and the BitmapField in a VFM, thus the bitmap field has been placed below the custom HFM, containing the edit field.

I hope I have described the exact UI layout I have presently, kindly help me out to resolve the issue. Thank you.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Focus to BitmapField

OK, that should work.

 

Can you replicate the problem just using an ordinary HFM, adding an ordinary EditField and then adding this, plus a Bitmap to an ordinary VFM?

 

If so, please post the code here and we can replicate. 

Developer
Posts: 103
Registered: ‎12-12-2011
My Device: Developer
My Carrier: Robosoft

Re: Focus to BitmapField

Hi,

 

I tried taking a simple HFM and edit field and also took a ButtonField. I added edit field to HFM and then added HFM and button field to a simple VFM, but no luck on that.

 

I am posting my earlier code below, hope I can get a solution.

 

//Main screen

public EnterNumberScreenManual(){
        
        super(NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR);
        
        mMainManager = new VerticalFieldManager(NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR |

                                                                                               USE_ALL_HEIGHT | USE_ALL_WIDTH);
                                          
        mSubManager = new VerticalFieldManager(NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR |

                                                                                                USE_ALL_WIDTH);
        
        mHFM = new HorizontalFieldManager(NO_VERTICAL_SCROLL | NO_VERTICAL_SCROLLBAR

                                                                                              |USE_ALL_HEIGHT | USE_ALL_WIDTH | FIELD_VCENTER){
                                             
                                        protected void sublayout(int maxWidth, int maxHeight) {
                                                 super.sublayout(maxWidth, maxHeight);
                                                 setPositionChild(getField(0), 0, (getPreferredHeight())/4);
            };
        };

        mHeader = new HeaderBarManager(mHeaderHikeBar, NO_VERTICAL_SCROLL |
                                                                                                                      NO_VERTICAL_SCROLLBAR);
        mLabelFieldMgr = new LabelFieldManger(USE_ALL_WIDTH, mPullNumText, mEnterItBelowText);
        
        mEditFieldMgr = new BitmapEditField(Manager.FIELD_HCENTER, mNumberEnterField,

                                                                                EditField.NO_NEWLINE |  EditField.FILTER_NUMERIC);
        mEditFieldMgr.setPadding(new XYEdges(10, 0, 10, 0));
        
        BitmapField bitmapBtn = new BitmapField(mNextBtn, FIELD_HCENTER | FOCUSABLE){

            protected void layout(int width, int height) {
                // TODO Auto-generated method stub
                super.layout(width, height);
                setExtent(mNextBtn.getWidth(), mNextBtn.getHeight());
            }
            
            protected void drawFocus(Graphics graphics, boolean on) {
                // TODO Auto-generated method stub
                super.drawFocus(graphics, true);
            }
            
            public boolean isFocusable() {
                // TODO Auto-generated method stub
                return true;
            }
            
            protected boolean navigationClick(int status, int time) {
                // TODO Auto-generated method stub

                if(Touchscreen.isSupported()){
                    return false;
                }else{
                    fieldChangeNotify(1);
                    return true;
                }
            }
            
            protected boolean touchEvent(TouchEvent message)
            {
                if(TouchEvent.DOWN == message.getEvent()){
                    FieldChangeListener listener = getChangeListener();
                    if(listener != null)
                        this.setFocus();
                }
                
                if (TouchEvent.CLICK == message.getEvent())
                {
                    FieldChangeListener listener = getChangeListener();
                    if (null != listener)
                        this.setFocus();
                        listener.fieldChanged(this, 1);
                }
                return super.touchEvent(message);
               // return true;
            }
            
        };
        
        bitmapBtn.setChangeListener(new FieldChangeListener() {
            
            public void fieldChanged(Field field, int context) {
                // TODO Auto-generated method stub
                // Code for handling the click event
            }
        });
        
        mSubManager.add(mLabelFieldMgr);
        mSubManager.add(mEditFieldMgr);
        mSubManager.add(bitmapBtn);
        
        mHFM.add(mSubManager);
                
        mMainManager.add(mHeader);
        mMainManager.add(mHFM);
        add(mMainManager);
    }

 

     //Custom HFM with edit field

     public class BitmapEditField extends HorizontalFieldManager{
    
    EditField mEditField;
    Bitmap mBackgroundImage;
    
    public BitmapEditField(long style, Bitmap backgroundImage, long editFieldStyle) {
        // TODO Auto-generated constructor stub
        super(style);
        mBackgroundImage = backgroundImage;
        
        mEditField = new EditField(editFieldStyle){
            
            protected void onFocus(int direction) {
                // TODO Auto-generated method stub
                super.onFocus(direction);
            }
            
            protected void onUnfocus() {
                // TODO Auto-generated method stub
                super.onUnfocus();
            }
            
        };
        add(mEditField);
    }
    
    public int getPreferredWidth() {
        // TODO Auto-generated method stub
        return mBackgroundImage.getWidth();
    }
    
    public int getPreferredHeight() {
        // TODO Auto-generated method stub
        return mBackgroundImage.getHeight();
    }
    
    protected void sublayout(int maxWidth, int maxHeight) {
        // TODO Auto-generated method stub
        super.sublayout(maxWidth, maxHeight);
        setExtent(getPreferredWidth(), getPreferredHeight());
        setPositionChild(getField(0), getPreferredWidth()/6, getPreferredHeight()/4);
    }
    
    protected void paint(Graphics graphics) {
        // TODO Auto-generated method stub
        graphics.drawBitmap(0, 0, getPreferredWidth(), getPreferredHeight(), mBackgroundImage, 0, 0);
        super.paint(graphics);
    }

}

 

Below is the image used for HFM:

 

img_content_input_call.png

 

 

Below is the image used for BitmapField:

 

btn_next_2.png

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Focus to BitmapField

Can we have the code that uses standard RIM components and demonstrates the problem please?

Developer
Posts: 103
Registered: ‎12-12-2011
My Device: Developer
My Carrier: Robosoft

Re: Focus to BitmapField

I tried using RIM componetns again and could find that the custom HFM is the culprit, which is not losing the focus. But I need to customize it as I need to have an image posted in my previous question and then add an edit field in this HFM.

 

Kindly suggest me the way to do this. I am attaching the snapshot of the UI layout required.snapshot.JPG

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Focus to BitmapField

This looks wrong to me:

 

   protected void sublayout(int maxWidth, int maxHeight) {
        // TODO Auto-generated method stub
        super.sublayout(maxWidth, maxHeight);
        setExtent(getPreferredWidth(), getPreferredHeight());
        setPositionChild(getField(0), getPreferredWidth()/6, getPreferredHeight()/4);
    }

 

But the first question is why does this have to be a HFM.  Why can't it just be a Manager. HFM does try to lay things out.  So try it with Manager.

 

Now on to your sublayout.

 

You are asking the Manager to lay things out (super.sublayout), then ignoring it.  So don't bother.  Remove the super.sublayout.  You still need to layout your EditField  So call layout on it, using the maximum size you can give it (which is your Bitmap size).  Now when you are positioning the EditField, you need to base this on the size that it has requested, not just tell it how big to be.  So once you lay it out,  check its required size (getWidth() and getHeight()), and make sure you position it properly using these. 

 

Once you have this working correctly, I suspect your problems will go away.

 

Developer
Posts: 103
Registered: ‎12-12-2011
My Device: Developer
My Carrier: Robosoft

Re: Focus to BitmapField

Hello,

 

I tried laying out the edit field using layout() in sublayout() of Manager, giving the width and height as that of the bitmap. But I am getting StackOverflowError. Can you please explain it using some sample code. Thanks in advance.

Developer
Posts: 19,636
Registered: ‎07-14-2008
My Device: Not Specified

Re: Focus to BitmapField

[ Edited ]

Would be better if you give us the code you have put in sublayout.

 

Remember you are calling layout on the EditField, not the Manager.

 

Edit: apologies, I should have said layourChild - see next post from arkadyz.