Skip to main content

Numeric textfield in blackberry

Please note these forums are being decommissioned and use the new and improved forums at
6 replies [Last post]
Joined: 2011-02-16

i have a normal numeric textfield like this:

textField.setInputModeOrder(new String[] {"123"});

and then a numeric textfield with password:

textField.setConstraint(TextField.NUMERIC | TextField.PASSWORD);
textField.setInputModeOrder(new String[] {"123"});

in lwuit 1.4 you had to hold the function button on the blackberry to actually get numbers instead of letter.

in lwuit 1.5 this almost solved. the first chacter always become a letter, but the second becomes a number.

This is tested on blackberrys like 9700 and 9900, you get the same behavoir on a simulator

the trouble is the numeric textfield with password.

even here the first character becomes a letter but then the code crashed and sais IllegalArgumentException.

App Error 104
Uncaught: IllegalArgumentException
JvmHostEGLMakeDisplayCurrent stub

so, do i need to hack the lwuit source to fix this or is there another way?

Reply viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
Joined: 2011-02-16

i found the solution, use the dataChangedListener:

textField.addDataChangeListener(new DataChangedListener() {
public void dataChanged(int type, int index) {
String text = textField.getText();
if (text.length() == 1) {
char testChar = text.charAt(0);

if (!Character.isDigit(testChar)) {
switch (testChar) {
case 'w':
textField.setText("1"); break;
case 'e':
textField.setText("2"); break;
case 'r':
textField.setText("3"); break;
case 's':
textField.setText("4"); break;
case 'd':
textField.setText("5"); break;
case 'f':
textField.setText("6"); break;
case 'z':
textField.setText("7"); break;
case 'x':
textField.setText("8"); break;
case 'c':
textField.setText("9"); break;

maybe not the best solution, but i don't need to hack the lwuit source

Joined: 2003-11-07

If you can produce a stack trace for the exception you got that might be quite helpful in fixing this bug (look in the ALT-LGLG log).

Regardless of that feel free to file a bug on this in the issue tracker. Thanks.

Joined: 2011-02-16

i will try to file a number of bugs because i get IllegalArgumentException all the time.

1.5 is a lot more unstable then 1.4 on blackberry.

Joined: 2003-11-07

We are working to get a 1.5.1 bugfix release out soon, although with the rate here at Oracle it might take us a while. Ideally if we can resolve the issue it would be very helpful if you can confirm the resolution is fixed in SVN so we don't break something else.

Joined: 2011-02-16

Sorry for the late reply, i have had some other things to do.

yes, i would gladly test SVN version of lwuit. I have downloaded the latest and i see that touch works much better in BB7.

The strange thing is that i get IllegalArgumentExceptions in the simulators but not on a real device (so far).

anyway, i tracked down one IllegalArgumentException to the method touchEvent in BlackberryTouchSupport, the message i got was "Attempt to delete a field that doesn't belong to the manager."

so i think the real error is in the finishEdit method in BlackBerryImplementation where lwuit does a delete on a field.

I have gotten some IllegalStateExceptions to, maybe i can find them.

Joined: 2003-11-07

printStackTrace() shows an error on the simulator but not on the device in RIM. Its remarkably stupid behavior.

I'll try to fix the issue with the delete soon, you will still get the error on the simulator (printStackTrace()) but it will work as expected on the device. If you have any hints to the IllegalStateException I will take a look at those.