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: 49
Registered: ‎06-02-2009
My Device: Curve8530, Curve8900, Storm9500
My Carrier: Airtel, vodaphone, Wifi
Accepted Solution

Button click fire automatically on touch screen devices

For touch screen devices, I am facing an issue. There are 2 buttons on my MainScreen "login" and "cancel"

 

By default there is foucs on "login" button. when user touch outside of logic button (some where on screen area) then login button click event fire automatically.

 

How can we solve this issue.... means if user touch somewhere outside of login button area then login button click event should not fire automatically ?

 

Please help

 

Thanks

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

Re: Button click fire automatically on touch screen devices

Two possibilities that I can think of immediately, might not be these, but this is where I would look first:

 

1) The touchEvent will be reflected to the Field with focus.  You need to reject it, by adding the following code to your touchEvent()

 

                int x = message.getX( 1 );
                int y = message.getY( 1 );
                if( x < 0 || y < 0 || x > getExtent().width || y > getExtent().height ) {
                        // Outside the field
                        return false;
                }

 

2) You have overridden a Manager's layout processing and confused it as where the Fields actually are.  This commonly happens with people moving things around inside a HorizontalFieldManager.  If you think it is this, then create your own Manager extending Manager, not HFM, and the problem will probably resolve itself.

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

Re: Button click fire automatically on touch screen devices

Hi,

 

I also was having same issue as you have when click on other area of touch screen it automatically call click event.

 

To prevent issue you need to track the click event.

 

Below is code that will help you to prevent the click event.

 

bmpnstatus = new BitmapField(status, FOCUSABLE)
                    {
                        protected boolean touchEvent(TouchEvent event)
                        {
                            int index = vfmstatus.getFieldAtLocation(event.getX(1), event.getY(1));
                            switch (event.getEvent())
                            {
                            case TouchEvent.CLICK:
                                if (event.getX(1) < 0 || event.getX(1) > getWidth()|| event.getY(1) < 0|| event.getY(1) > getHeight())
                                {
                                    isTouch = false;
                                    return false;
                                }
                                else
                                {
                                    if (vfmstatus.getField(index).equals(bmpstatus))
                                    {
                                        CommonInterface.focusType = 5;
                                        if (!CommonInterface.isOptProgress)
                                            getDeviceStatus();
                                    }
                                }
                                break;
                            }
                            return super.touchEvent(event);
                        }

                        protected boolean navigationClick(int status, int time)
                        {
                            if (!isTouch)
                                isTouch = true;
                            else
                            {
                                CommonInterface.focusType = 5;
                                if (!CommonInterface.isOptProgress)
                                    getDeviceStatus();
                            }
                            return true;
                        }

                        public void onUnfocus() {
                            super.onUnfocus();
                            invalidate();
                        }

                        protected void paint(Graphics graphics)
                        {
                            super.paint(graphics);
                            if (isFocus())
                            {
                                graphics.setGlobalAlpha(128);
                                graphics.setColor(Color.LIGHTBLUE);
                                graphics.fillRect(0, 0, getWidth(), getHeight());
                            }
                        }
                    };

 

Here in Code with Red mark is solution for your problem that will stop the false click of button.

 

Regards,

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

Re: Button click fire automatically on touch screen devices

The code supplied above is similar to the code I had already supplied.  However it is incomplete, since events can be driven on Unclick as well as Click.  I recommend using the code I supplied and using it as the first bit of processing in the touchEvent() method so that you ignore all touchEvents that are external to the Field.   

 

        protected boolean touchEvent(TouchEvent event)
        {

                int x = message.getX( 1 );
                int y = message.getY( 1 );
                if( x < 0 || y < 0 || x > getExtent().width || y > getExtent().height ) {
                        // Outside the field
                        return false;
                }

Developer
Posts: 151
Registered: ‎09-28-2012
My Device: Blackberry Developer
My Carrier: Aircel

Re: Button click fire automatically on touch screen devices

In BB 7.1 bydeafault the focus comes on first field of the screen...

 

you have to handle this as per peter suggest you you can try that..


----------------------------------------------------------
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.