2

I wants to create Text Field which allows all number > 0 So I have Done Such Like this :

TextField textField = new TextField();    
textField.setConstraint(TextField.NUMERIC);

But I am not getting How to restrict user to enter Zero. Help Me to sort out this thing.....!!!

Satyam Koyani
  • 4,236
  • 2
  • 22
  • 48

1 Answers1

0

You may have to extend the TextEditor class and ensure that Zero is not painted on the screen. Another way, which is simpler is to validate the user entered data, and if it contains zero, display a prompt that zero's are not allowed.

Ajibola
  • 1,218
  • 16
  • 28
  • I dont's wants to handle manually I wants to put restriction to user so that i have to go for first option by extending TextEditor class.I tried that but i cannot find any TextEditor class. – Satyam Koyani Dec 06 '12 at 10:12
  • i have been using lwuit s40 for nokia, but standard lwuit doesnt come with the text editor class. You can look into overiding the KeyPress and KeyRelease of the form, that way you can customize what happends for every key stroke and ignore the zero when it is entered. Also you can look into VirtualKeyboard.java in the source. – Ajibola Dec 06 '12 at 11:14
  • Ajibola Can you just tell me how to do that with keypress event ? – Satyam Koyani Dec 07 '12 at 06:18
  • It is covered in detail here : http://stackoverflow.com/questions/5907742/override-keypress-method-in-lwuit – Ajibola Dec 09 '12 at 06:35