Download presentation
Presentation is loading. Please wait.
Published byQuentin Berry Modified over 8 years ago
1
Sunday – 1 August 2010
2
How to create new mobile device application project How to compile and package mobile device project, and make it installable on mobile phone How to create basic navigation flow How to display data/information on StringItem, Ticker How to get data input from user using TextField
3
By the end of this Lab session, you should be able to: Get numerical data from TextField Perform basic calculation (unit conversion) using Java method Perform Error Handling, Display AlertBox Use POPUP ChoiceGroup Create a robust TextField that will only accept numerical value
4
Your task is to develop Unit Conversion mobile application Convert from Meter metric unit to Feet Formula ? Feet = meter * 3.281
5
Create 1 TextField, rename to “Value” Create one StringItem, rename to Result Add one ScreenCommand to perform conversion Other consideration… Create a new java method for conversion meterToFeet(double value){}
6
Warning: you might want to create Double or Float variable and use Double.parseDouble or Float.parseFloat to change String variable to numerical value You can change numerical value back to String by using Double.valueOf(string) or Float.valueOf(string)
7
textField.getString() Get Value from TextField Create java method to perform calculation Still remember how to create method? meterToFeet(double value) Perform calculation stringItem.setText(value) Set the converted value to StringItem
8
What do you remember from yesterday’s lesson? What are the problem that you encounter with this solution? How to improve it?
9
TextField have “Input Constraints” properties that can change its behavior to user input Try to change it to “Numeric” or “Decimal”. What did you see?
10
Sometimes it is nice to be able to prompt user to input the correct data In this case, we use Alert Use “Alert” to notify user that they need to input value greater than 0
11
If (value <=0.0) { Alert alert = new Alert("Please enter positive value"); switchDisplayable(alert,getForm()); }
13
Did you notice the Exception text when you leave the TextField blank? As an exercise, try to handle that exception, using common java knowledge, and remind user that they have to enter value to get conversion result.
15
How about giving option to user to convert from other units too? So we should use ChoiceGroup
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.