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
Developer
Posts: 191
Registered: ‎04-02-2013
My Device: BlackBerry Bold 9900
My Carrier: developer

How to add click event in editfield containing image

Hi

I want to create an editfield that contains an image and when i click on that image a dialog box gets open.

And i am doing like this

 

EditField edit = new EditField()
        {

            
            protected void paint(Graphics graphics)
            {
                graphics.drawBitmap(30, 1, 30, 30, img, 10, 10);
                super.paint(graphics);
            }
          
            
        };

 

Now if i start enter the the text i get the message.But i want when i entered the whole text and clcik the image then i get the message.

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

Re: How to add click event in editfield containing image

It is not possible to do this in the way you are trying to do.

 

Instead you need to create two Fields, the EditField and the 'button' displaying the image, then combine them next to each other, using a HorizontalFieldManager. 

 

For a new comer to BlackBerry Java programming this is not an trivial exercise, so I suggest you start by creating the button that displays an image and is clickable.  This requirement has been requested before, so please search the forum for sample code.

 

Once you have this, then try to combine it with an EditField.  You may have problems because the EditField will try to take up all the width, so the best option is the add the 'Button' to the the HorizontalFieldManager then the edit field.

 

I also recommend a stroll around the Java Micro-site which will help you get to understand all the concepts better - here is the URL to the UI part

http://developer.blackberry.com/bbos/java/documentation/uiquickref_intro_1986602_11.html

Developer
Posts: 191
Registered: ‎04-02-2013
My Device: BlackBerry Bold 9900
My Carrier: developer

Re: How to add click event in editfield containing image

I have already done it by adding the editfield and BitmapField in a horizontal field manager. But the problm is i want to create the border in edit field and add the bitmap inside the editfield and make the bitmap as clickable.

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

Re: How to add click event in editfield containing image

While what you are trying to do is technically possible, it is quite complicated and you need to manage a number of things carefully, for example focus indication, especially when the user is using the trackpad to move focus.

 

Instead I suggest you put a border around your HorizontalFieldManager to make it look like the EditField and BitmapField are part of the same control.  The effect will be much the same and it is a whole lot easier to code. 

Developer
Posts: 191
Registered: ‎04-02-2013
My Device: BlackBerry Bold 9900
My Carrier: developer

Re: How to add click event in editfield containing image

Hey i have done ot through HorizontalField Manager Bi=ut Bitmap image is not visible.

Here is the code..

 

        HorizontalFieldManager m = new HorizontalFieldManager();

        
        EditField edit1 = new EditField();
        m.add(edit1);
        
        
        BitmapField bitmapFeid = new BitmapField(a,BitmapField.FOCUSABLE)
        {
            protected void layout(int width, int height)
            {
                setExtent(50, 50);
                super.layout(50,50);
            }
            protected boolean navigationClick(int arg0, int arg1)
            {
                Dialog.inform("Ok");
                return true;
            }
        };
        m.add(bitmapFeid);
        
        Border roundedBorder = BorderFactory.createRoundedBorder(new XYEdges(10,10,10,10), Color.BLACK, Border.STYLE_FILLED);
        Background bg = BackgroundFactory.createSolidBackground(Color.WHITE);
        m.setBackground(bg);
        m.setBorder(roundedBorder);
        add(m);

Regular Contributor
Posts: 66
Registered: ‎08-28-2010
My Device: 9630

Re: How to add click event in editfield containing image

 

 

Hello,

 

Try to modify as one line and try and see if it works..

 

 HorizontalFieldManager m = new HorizontalFieldManager(HorizontalFieldManager.USE_ALL_WIDTH);

 

Regards,

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

Re: How to add click event in editfield containing image

"... Bitmap image is not visible"

 

I mentioned this possibility in my first post:

"Once you have this, then try to combine it with an EditField.  You may have problems because the EditField will try to take up all the width, so the best option is the add the 'Button' to the the HorizontalFieldManager then the edit field."

 

Try this and get your processing working correctly.  Then we can work on setting width appropriately so that both Fields are visible. 

 

Also do you really want this?

 

            protected void layout(int width, int height)
            {
                setExtent(50, 50);
                super.layout(50,50);
            }

 

I have two issues here:

1) You are saying that, regardless of device type, your button will take up 50 pixels.  You will find that on screen this button takes up markedly different amounts of space depending on the screen resolution of the BlackBerry device you are running on.

2) When you call layout, any setExtents you have previously done will in fact be ignored.  So your setExtent is redundant.

 

I am not sure you have got to grips with customizing Fields and Managers.  If you really want to do this, can I suggest you review the following KB articles:

 

http://supportforums.blackberry.com/t5/Java-Development/Create-custom-fields/ta-p/444962

http://supportforums.blackberry.com/t5/Java-Development/Create-a-custom-layout-manager-for-a-screen/...

http://supportforums.blackberry.com/t5/Java-Development/How-to-Extend-Manager/ta-p/446749

 

Developer
Posts: 191
Registered: ‎04-02-2013
My Device: BlackBerry Bold 9900
My Carrier: developer

Re: How to add click event in editfield containing image

Regular Contributor
Posts: 66
Registered: ‎08-28-2010
My Device: 9630

Re: How to add click event in editfield containing image

hello,

 

please go through below this two link that will help you to add image as edittextfield.

 

http://supportforums.blackberry.com/t5/Java-Development/How-to-create-Edit-Field-looks-like-below-im...

 

http://stackoverflow.com/questions/8050767/customize-edit-field-on-blackberry

 

Let me know if it help you or not.

 

Regards,

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

Re: How to add click event in editfield containing image

"....can i add text into this ?"

 

Is this a different question to the one we were working on?

 

How have you got on adding the image first?