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: 157
Registered: ‎03-03-2009
My Device: Not Specified
Accepted Solution

buttonField does not get focus

On a screen, I added a few text boxes and below that a buttonField:

 

 

ButtonField registerButton = new ButtonField("REGISTER", ButtonField.CONSUME_CLICK);
registerButton.setChangeListener(this);
add(registerButton);

 

 

On storm 2, when I touch the button, it is not highlighted at all. The cursor stays with the first text box.

 

On Torch, I have to keep on sliding from the top text box toward the button to eventually get it highlighted.

 

What I want is to touch the button and it gets highlighted and the fieldChanged method gets called. What could be the problem that prevents it from happenning?

 

Thanks.

Highlighted
Regular Contributor
Posts: 64
Registered: ‎01-27-2011
My Device: Not Specified

Re: buttonField does not get focus

Try ButtonField registerButton = new ButtonField("REGISTER", ButtonField.CONSUME_CLICK | Field.FOCUSABLE);

Developer
Posts: 604
Registered: ‎12-27-2010
My Device: Not Specified

Re: buttonField does not get focus

Are your text boxes custom fields, or anything else that can get the focus?

Developer
Posts: 157
Registered: ‎03-03-2009
My Device: Not Specified

Re: buttonField does not get focus

The text box is a VerticalFieldManager that contains a BasicEditField. The manager draws a border around the edit field

Developer
Posts: 157
Registered: ‎03-03-2009
My Device: Not Specified

Re: buttonField does not get focus

adding Field.FOCUSABLE does not help. It seems that the focus just get trapped in the text box....

 

 

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

Re: buttonField does not get focus

1) Have you written the text box code yourself of have you taken it from somewhere on the Net? If the latter, I hope they are not based on the old "Pimp my Object: Creating a text box field" - that one has an infinite loop of painting and invalidating and might easily throw off your focusing.

There is a "TextBoxField revisited" knowledge base article with much more robust code and a slightly neater looking result.

 

2) Do you have any onUnfocus overrides in your text boxes? If yes, do they ever try to set focus on anything?

----------------------------------------------------------
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: 157
Registered: ‎03-03-2009
My Device: Not Specified

Re: buttonField does not get focus

1) using the "textbox revised" codes from the dev knowledge, I got the same result. focus does not go to the button

 

2) I do not have any

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

Re: buttonField does not get focus

Any touchEvent overrides?

----------------------------------------------------------
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: 157
Registered: ‎03-03-2009
My Device: Not Specified

Re: buttonField does not get focus

no. but with a small correction (which may or may not make a big difference)...

 

The textbox and button are added to a VerticalFieldManager which is then added to the screen. (Instead of being added directly to the screen)

 

The VerticalFieldManager is screen width. The textbox and button are less than the screen width.

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

Re: buttonField does not get focus

Weird... That shouldn't make any difference. Can you replace text boxes with simple edit fields and see if the result changes?

----------------------------------------------------------
please click 'Accept Solution' on posts that provide the solution to the question you've posted. Don't say "Thanks", press 'Like' button instead!