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: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Help Focus on managers

Of course it won't work without touch screen. navigationClick and other stuff are up to you do decide what to do.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
Posts: 23
Registered: ‎07-14-2011
My Device: 9300

Re: Help Focus on managers

Can you help me again?, the code seems to works right but it gets a RuntimeException... here is the code how I am trying to use it.

 

protected boolean touchEvent(TouchEvent message) {
		  int x = message.getX(1);
		  int y = message.getY(1);
		  
		  int index = this.getFieldAtLocation(x, y);
		  Field selected = this.getField(index);
		  ProfileStatusHorizontalItem pshi = (ProfileStatusHorizontalItem)selected;
		  
		  if (message.getEvent() == TouchEvent.DOWN) {
		    if (x >= 0 && x < getWidth() && y >= 0 && y < getHeight()) {
		      this.getNf().setFocus();
		      //Dialog.alert(""+this);
		    }
		  }
		  return super.touchEvent(message);
		}

 I am calling this method in a Manager which works as a list of other managers(ProfileStatusHorizontalItem) and this last one contains other fields... I did not use a listField cause the profilestatushorizontalItem could have different height.

Contributor
Posts: 23
Registered: ‎07-14-2011
My Device: 9300

Re: Help Focus on managers

Sorry, there is an error on the code I posted, change 

 

this.getNf().setFocus();

to 

pshi.getNf().setFocus();

 But still not working =(

Developer
Posts: 2,268
Registered: ‎07-08-2009
My Device: various

Re: Help Focus on managers

Next time please cite the type of exception, the message (if any) and the line which causes the exception. Do some debugging before asking here - it might help you find out the reason of the problem on your own.

 

I can only guess that since you are not checking selected to be non-null you risk getting NullPointerException every now and then.

 

In addition, you don't have to find out the NullField inside pshi. Setting focus to a Manager sets focus to its first focusable field. So if (selected != null) selected.setFocus(); should be sufficient.

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!
Contributor
Posts: 23
Registered: ‎07-14-2011
My Device: 9300

Re: Help Focus on managers

Sorry dude!! I debugged and the field wasn't empty, I think It was the Dialog.alert(""+phi), now it works, but works the same with less lines as you told me last post. And I gonna try to describe better :Clap:

Trusted Contributor
Posts: 184
Registered: ‎11-26-2010
My Device: Not Specified

Re: Help Focus on managers

Hi Chostislas, was sneaking through your code, can you suggest me how you implemented click for non touch phones? I am developing for BB BOLD 9780

 

A Y

Contributor
Posts: 23
Registered: ‎07-14-2011
My Device: 9300

Re: Help Focus on managers

If you are using managers and you want to focus all the manager layout just add a NullField to the manager which shoudl be focusable, and set all the other fields non focusable, then override the navigationClickEvent method which code is similar to the touchEvent that i posted, just consider that on navigationClickEvent you do not need to get the (x,y) positions and look which Field was clicked...

Trusted Contributor
Posts: 184
Registered: ‎11-26-2010
My Device: Not Specified

Re: Help Focus on managers

Thanks a lot buddy, that did the trick! I am posting it below, it might help someone else, 

 

VerticalFieldManager parentManager = new VerticalFieldManager(VerticalFieldManager.VERTICAL_SCROLL|VerticalFieldManager.VERTICAL_SCROLLBAR){
		protected boolean navigationClick(int status, int time)
		{
			int index;
	System.out.println("CLICKED!!!!!!!!!!);
if ((status & KeypadListener.STATUS_FOUR_WAY) == KeypadListener.STATUS_FOUR_WAY) {
				
index = this.getFieldWithFocusIndex();

		}
		System.out.println("OUTPUTTTTTTTTTTTTTTT"+this.getFieldWithFocusIndex());
	return true;
}
	};