Win a copy of The Business Blockchain this week in the Cloud forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

convert from string to int

 
Henk Rog
Ranch Hand
Posts: 36
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I have made an application with a textfield. The value entered in the textfield
should be greater than a certain int. How can I do that? I get an error:
can't convert from string to int.
thanks
 
David Price
Ranch Hand
Posts: 93
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
To limit the text field to numeric input, use the NUMERIC constraint in its constructor.
To convert its value to an integer, use method Integer.parseInt(String).
To check each value the user enters, add an ItemStateListener to the text field's enclosing Form, and in the itemStateChanged method, check if it's the text field that changed, and if so, whether the new value is OK. If not, display an Alert, and probably set the text field back to the preceding valid value. (Note: I've not used ItemStateListener myself - this is just from reading the JavaDocs).
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic