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
New Contributor
easyp
Posts: 5
Registered: ‎04-20-2010
My Device: 8700
Accepted Solution

How to select and edit LabelFields / ButtonFields 2D Array

Hi there everyone, I'm new here and I'm new to blackberry development.

For a student project I'm working on, I have a 2D array of ButtonFields, (which I may change to LabelFields if its easier) which I am using to create a Sudoku grid.

I understand it's really basic but I want to the user to be able to just scroll through the 2D array to a particular cell and be able to type in a number using the keypad to instantly change the label of the ButtonField or LabelField, ie their guess of the Sudoku. 

I'm really having trouble as I'm not familiar with how the blackberry accepts user input and how this can be used with the setText method.

 

So essentially i'd like some sort of way of determining which cell is currently selected (without it being clicked) and then for this currently selected cell to have the setText() method applied to it


Can anybody help me? I can post up code if it helps but I'm not sure it will as you'll al understand how basic it is.

Thank you in advance and I hope I can return the favour soon

Developer
simon_hain
Posts: 16,282
Registered: ‎07-29-2008
My Device: Z10 LE, Z30, Passport

Re: How to select and edit LabelFields / ButtonFields 2D Array

you can use a focuschangelistener to be aware of focus changes. or call getLeafFieldWithFocus() to retrieve the current field.

 

you cannot make buttonfields editable, but you can read the user input and process it.

 

for sudoku you need only the numbers, you can use the keyChar method to read entered characters.

check if your focused field is one of your buttons. check if the entered char or alted char (Keypad.getAltedChar)  is a digit (Characters.isDigit).

 

you can call setText on the buttonfield.

----------------------------------------------------------
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.
@SimonHain on twitter
New Contributor
easyp
Posts: 5
Registered: ‎04-20-2010
My Device: 8700

Re: How to select and edit LabelFields / ButtonFields 2D Array

thanks a lot for your help, its worked!