Skip to main content

Numeric textfield in blackberry

6 replies [Last post]
dafo75
Offline
Joined: 2011-02-16
Points: 0

i have a normal numeric textfield like this:

textField.setConstraint(TextField.NUMERIC);
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.
dafo75
Offline
Joined: 2011-02-16
Points: 0

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;
default:
textField.setText("");
break;
}
}
}
}
});

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

vprise
Offline
Joined: 2003-11-07
Points: 0

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.

dafo75
Offline
Joined: 2011-02-16
Points: 0

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.

vprise
Offline
Joined: 2003-11-07
Points: 0

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.

dafo75
Offline
Joined: 2011-02-16
Points: 0

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.

vprise
Offline
Joined: 2003-11-07
Points: 0

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.