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: 151
Registered: ‎09-28-2012
My Device: Blackberry Developer
My Carrier: Aircel
Accepted Solution

problem on touchEvent

Hello,

 

i have a gridfieldmanager and i am overriding touchEvent(TouchEvent message) method inside the gridfieldmanager ,my problem is that when i am clicking on the empty part of the gridfieldmanager ,adjcent field is consumig click ..how can i stop clicking on adjcent field when clicking on empty part of grid...


----------------------------------------------------------
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.
Developer
Posts: 19,623
Registered: ‎07-14-2008
My Device: Not Specified

Re: problem on touchEvent

Try adding this code:

 

        protected boolean touchEvent(TouchEvent message) {
                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;
                }

.... rest as before

 

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

Re: problem on touchEvent

Dear Peter..thank you for your promt reply..its help me a little..

but i have already seted the Excent of grid when i am clicking  outside the grid its not taking changes its working fine,my concern is that..when i am clicking on the empty part which is not covered by any field is also reflecting on the adjcent fields...

 

here is my sample code..

 

grid = new GridFieldManager(4,4, GridFieldManager.AUTO_SIZE | NON_FOCUSABLE ) {
public void sublayout(int width,int height) {
super.sublayout(lower_bitmap.getWidth()-lower_bitmap.getWidth()/3, lower_bitmap.getHeight());
setExtent(lower_bitmap.getWidth()-lower_bitmap.getWidth()/3, lower_bitmap.getHeight());
}

protected boolean touchEvent(final TouchEvent message) {
switch(message.getEvent())
{
    case TouchEvent.CLICK:
    try {
          int x = message.getX( 1 );
          int y = message.getY( 1 );
          // Function for changing questions
       

           if( x < 0 || y < 0 || x > getExtent().width || y > getExtent().height ) {
          / / Outside the field
           return false;
         }
         else {
       change_questions();
       }  

   }
   catch (Exception e) {
   System.out.println("Exception in getting basic details in touch event="+e);
  }
  }
   return super.touchEvent(message);
 }
};

 

i want to call my change_questions(); method only when i click on field added to gridfield manager not clicking on the empty part...

 

thanx..

 

------------------------------------------------


----------------------------------------------------------
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.
Developer
Posts: 19,623
Registered: ‎07-14-2008
My Device: Not Specified

Re: problem on touchEvent

It is unusual to have a Manager detect touchEvent.  You would normally do that in a Field - which is what I would recommend in this case to resolve your problem.   Or create some mechanism so that you can detect an empty position. 

 

Also I do not recomended setting the extent for a Maanger, haivng just asked it to lay itself out.  If you need to do that then you should really consider creating your own Manager. 

 

I have had issues with GridFieldManager and I would not use it - instead I use TableLayoutManager. 

http://supportforums.blackberry.com/t5/Java-Development/Create-a-rich-UI-layout-with-TableLayoutMana...

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

Re: problem on touchEvent

Dear Peter..thanx a lot for your valuable support...

i have fix the issue....doing like...

 

if( message.getX(1) > focus_field.getExtent().x && message.getX(1) < (focus_field.getExtent().x + focus_field.getExtent().width) && message.getY(1) > focus_field.getExtent().y && message.getY(1) < (focus_field.getExtent().y + focus_field.getExtent().height) )

{

      change_questions();

}
else  {

      //Do nothing

}

 

Now its working like i want...

 

:smileyhappy:


----------------------------------------------------------
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.
New Contributor
Posts: 2
Registered: ‎09-12-2013
My Device: 9800
My Carrier: Airel

Re: problem on touchEvent

thanx a lot guys...

 

this post helps me ...

 

i was facing the same issue...