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: 225
Registered: ‎09-29-2010
My Device: Limited Edition Z10, Playbook
My Carrier: Airtel

Re: Problem with touchEvent and click

Thanks for the help Smiley Happy

I tried your code, but there is an issue

 

coordinate for X axis are fine and accurate, but for Y axis there is difference of 1 field.

 

Code for creating fields

                vfm = new VerticalFieldManager(VerticalFieldManager.USE_ALL_HEIGHT|VerticalFieldManager.FIELD_HCENTER);
		vfm.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3,3,3,3)));
		vfm.setBackground(BackgroundFactory.createSolidTransparentBackground(Color.BLACK, 205));
		System.out.println("1");
		
		ht = new MyBasicEditField("Field1 : ", "Select", 13, BasicEditField.FILTER_NUMERIC,9);
		ht.setMargin(new XYEdges(top,right,0,left));
		ht.setBorder(BorderFactory.createRoundedBorder(new XYEdges(3,3,0,3)));
		ht.setBackground(BackgroundFactory.createSolidTransparentBackground(Color.BLACK,214));
		//ht.setPadding(new XYEdges(top/5, right/7, bottom/5, left/7));
		
		wt = new MyBasicEditField("Field2 : ", "Select", 13, BasicEditField.FILTER_NUMERIC,9);
		wt.setMargin(new XYEdges(0,right,0,left));
		wt.setBorder(BorderFactory.createRoundedBorder(new XYEdges(0,3,0,3)));
		wt.setBackground(BackgroundFactory.createSolidTransparentBackground(Color.BLACK,214));
		//wt.setPadding(new XYEdges(top/5, right/7, bottom/5, left/7));
		
		age = new MyBasicEditField("Field3 : ", "Select", 13, BasicEditField.FILTER_NUMERIC,9);
		age.setMargin(new XYEdges(0,right,bottom/7,left));
		age.setBorder(BorderFactory.createRoundedBorder(new XYEdges(0,3,3,3)));
		age.setBackground(BackgroundFactory.createSolidTransparentBackground(Color.BLACK,214));
                //age.setPadding(new XYEdges(top/5, right/7, bottom/5, left/7));
		

 Code for detecting touch

 

protected boolean touchEvent(TouchEvent event) {
		 
		 System.out.println("Field1:"+ht.getExtent().x+", "+ht.getExtent().y+", "+(ht.getExtent().width+ht.getExtent().x)+", "+(ht.getExtent().height+ht.getExtent().y) );
		 System.out.println("Field3:"+wt.getExtent().x+", "+wt.getExtent().y+", "+(wt.getExtent().width+wt.getExtent().x)+", "+(wt.getExtent().height+wt.getExtent().y) );
		 System.out.println("Field3:"+age.getExtent().x+", "+age.getExtent().y+", "+(age.getExtent().width+age.getExtent().x)+", "+(age.getExtent().height+age.getExtent().y) );
		 
}		 

 

 

I clicked on 150:150 on Field3(mouse not visible)

screenshot.JPG

 

Result :

[0.0] Field1 :51, 68, 303, 94
[0.0] Field2 :51, 94, 303, 117
[0.0] Field3 :51, 117, 303, 143
[0.0] !!!!!X : Y 150:150 @@@@@@ event 13569

 

 

What am I doing wrong???

 

Abhinav Tyagi

 

 

Blackberry Z10-Limited Edition
Blackberry Playbook (won in free playbook offer)
My Apps : pAinT, HealthMeter, Shoot
Developer
Posts: 225
Registered: ‎09-29-2010
My Device: Limited Edition Z10, Playbook
My Carrier: Airtel

Re: Problem with touchEvent and click

In the screen I am clicking on Field3 (150:150) but in Console Field3 is from 117 to 143 vertically !!!
Blackberry Z10-Limited Edition
Blackberry Playbook (won in free playbook offer)
My Apps : pAinT, HealthMeter, Shoot
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Problem with touchEvent and click

 


CMY wrote:

You would use the x,y coordinates passed in the TouchEvent to see if they fall in a fields extent. The screen size does not matter since you will check each field to see if it lies within it's extent. I use all custom fields, so I can't show you exact code, but it would be of this nature:

 

if( TouchEvent.getX(1) > Field.getExtent().x && 
TouchEvent.getX(1) < (Field.getExtent().x+Field.getExtent().width) && TouchEvent.getY(1) > Field.getExtent().y &&
TouchEvent.getY(1) < (Field.getExtent().y+Field.getExtent().height) ){ //Field has been touched } 

 

Don't forget that the validity of this code depends on whether touchEvent is defined on the Manager's or the Field's level. If you override touchEvent of the parent Manager of your fields, then the above code is correct. If you override touchEvent of the Fields themselves, drop getExtent().x and getExtent().y from the equation (use zeroes instead).

And if you override touchEvent on the Screen level, those getExtent wont help you at all. Search the forums for getFieldExtent then - a nice piece of code by Peter Strange. If you go that route, don't forget to factor in the Screen's scroll positions.

 

I know it sounds confusing, but such is BlackBerry programming in general. I could put it in a short sequence: "TouchEvent.getX and TouchEvent.getY are translated relative to the Field's upper left corner". See if it clarifies things Smiley Happy

 

Also, those '>' (greater than) signs should be replaced with '>=' (greater or equal).

 

Good luck!

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 225
Registered: ‎09-29-2010
My Device: Limited Edition Z10, Playbook
My Carrier: Airtel

Re: Problem with touchEvent and click

check my post here

http://supportforums.blackberry.com/t5/Java-Development/Solution-to-touchEvent-and-click-issue/td-p/...

 

It's working now

 

Abhinav Tyagi

Blackberry Z10-Limited Edition
Blackberry Playbook (won in free playbook offer)
My Apps : pAinT, HealthMeter, Shoot
Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various
My Carrier: various

Re: Problem with touchEvent and click

The code there won't even compile - touchEvent needs to return a boolean. I'm very suspicious of this "solution".

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Developer
Posts: 225
Registered: ‎09-29-2010
My Device: Limited Edition Z10, Playbook
My Carrier: Airtel

Re: Problem with touchEvent and click

Hey  I just wrote the code in a hurry !

there is a return statement in both functions Smiley Tongue

 

Abhinav

Blackberry Z10-Limited Edition
Blackberry Playbook (won in free playbook offer)
My Apps : pAinT, HealthMeter, Shoot
Developer
Posts: 225
Registered: ‎09-29-2010
My Device: Limited Edition Z10, Playbook
My Carrier: Airtel

Re: Problem with touchEvent and click

Hi Praveen,

if your issue is resolved then please mark this as "Solved"

Thanks
Abhinav
Blackberry Z10-Limited Edition
Blackberry Playbook (won in free playbook offer)
My Apps : pAinT, HealthMeter, Shoot