An Edit is a field used to show and alter texts. Also known as UITextField on Swift and input on HTML. There also is some variations, like Outlined Edit, Calculator Edit, Password Edit, etc.
Examples
In most applications is necessary to remove the background from the object and change the color of the element so that it is better viewed.
packagecom.totalcross;importtotalcross.sys.Settings;importtotalcross.ui.Edit;importtotalcross.ui.MainWindow;importtotalcross.ui.dialog.MessageBox;importtotalcross.ui.gfx.Color;importtotalcross.util.UnitsConverter;publicclassHelloWorldextendsMainWindow {privateEdit simpleEdit;privateint GAP =UnitsConverter.toPixels(DP +15);publicHelloWorld(){setUIStyle(Settings.MATERIAL_UI); } @OverridepublicvoidinitUI(){try{ simpleEdit =newEdit();simpleEdit.caption="Simple Edit";simpleEdit.transparentBackground=true;simpleEdit.captionColor=Color.RED;simpleEdit.setForeColor(Color.RED);add(simpleEdit, LEFT + GAP, AFTER + GAP); } catch (Exception e) {MessageBox.showException(e,true); } }}
Numeric edit
In some situations, entry should be limited to numbers.
packagecom.totalcross;importtotalcross.sys.Settings;importtotalcross.ui.Edit;importtotalcross.ui.MainWindow;importtotalcross.ui.dialog.MessageBox;importtotalcross.util.UnitsConverter;publicclassHelloWorldextendsMainWindow {privateEdit numericEdit;privateEdit calculatorEdit;privateint GAP =UnitsConverter.toPixels(DP +15);publicHelloWorld(){setUIStyle(Settings.MATERIAL_UI); } @OverridepublicvoidinitUI(){try{ numericEdit =newEdit();numericEdit.caption="NumericBox Edit";numericEdit.setMode(Edit.CURRENCY);numericEdit.setKeyboard(Edit.KBD_NUMERIC); add(numericEdit, LEFT + GAP, AFTER + GAP); calculatorEdit =newEdit();calculatorEdit.caption="Calculator Edit";calculatorEdit.setMode(Edit.CURRENCY,true);add(calculatorEdit, LEFT + GAP, AFTER + GAP); } catch (Exception ee) {MessageBox.showException(ee,true); } }}
Password Edit
If the entry is a password, it should not be possible to see it.
packagecom.totalcross;importtotalcross.sys.Settings;importtotalcross.ui.Edit;importtotalcross.ui.MainWindow;importtotalcross.ui.dialog.MessageBox;importtotalcross.util.UnitsConverter;publicclassHelloWorldextendsMainWindow {privateEdit passwordShowEdit;privateEdit passwordHidenEdit;privateint GAP =UnitsConverter.toPixels(DP +15);publicHelloWorld(){setUIStyle(Settings.MATERIAL_UI); } @OverridepublicvoidinitUI(){try{ passwordShowEdit =newEdit();passwordShowEdit.caption="Password Edit (last character is shown)";passwordShowEdit.setMode(Edit.PASSWORD);add(passwordShowEdit, LEFT + GAP, AFTER + GAP); passwordHidenEdit =newEdit();passwordHidenEdit.caption="Password Edit (all characters are hidden)"; passwordHidenEdit.setMode(Edit.PASSWORD_ALL);add(passwordHidenEdit, LEFT + GAP, AFTER + GAP); }catch (Exception ee) {MessageBox.showException(ee,true); } }}
Edit shapes
To receive different input formats, which are not predefined in TotalCross.
packagecom.totalcross;importtotalcross.sys.Settings;importtotalcross.ui.Edit;importtotalcross.ui.MainWindow;importtotalcross.ui.dialog.MessageBox;importtotalcross.util.UnitsConverter;publicclassHelloWorldextendsMainWindow {privateEdit calendarEdit;privateEdit timerEdit;privateEdit maskedEdit;privateint GAP =UnitsConverter.toPixels(DP +15);publicHelloWorld(){setUIStyle(Settings.MATERIAL_UI); } @OverridepublicvoidinitUI(){try{ calendarEdit =newEdit("99/99/99");calendarEdit.caption="Calendar Edit";calendarEdit.setMode(Edit.DATE,true);add(calendarEdit, LEFT + GAP, AFTER + GAP); timerEdit =newEdit("99"+Settings.timeSeparator+"99"+Settings.timeSeparator+"99");timerEdit.caption="TimeBox Edit (24-hour format)";timerEdit.setValidChars("0123456789AMP");timerEdit.setMode(Edit.NORMAL,true);timerEdit.setKeyboard(Edit.KBD_TIME);add(timerEdit, LEFT + GAP, AFTER + GAP); maskedEdit =newEdit("999.999.999-99");maskedEdit.caption="Masked Edit (999.999.999-99)";maskedEdit.setMode(Edit.NORMAL,true);maskedEdit.setValidChars(Edit.numbersSet);add(maskedEdit, LEFT + GAP, AFTER + GAP); }catch (Exception ee){MessageBox.showException(ee,true); } }}
stores the value that will be used by the clear() method to switch texts
Byte
captalise
used to modify the the letter case from the text within the Edit:
ALL_NORMAL: normal case
ALL_LOWER: all lowercase
ALL_UPPER: all uppercase
String
caption
The Edit's placeholder text
boolean
forceBackgroundColor
forces the edit tu use the background color on it, must be used with UIColors.sameColors setted to true
Type
Name
Description
Constructor
Edit( )
Creates a box for user input
Constructor
Edit(String mask)
Creates a box for user input, but with a mask
void
setMode(byte mode)
Used to change the mode value to one of the accepted ones by the mode constants, without masking. To enable masking, you should use the setMode(byte mode, boolean maskedEdit) method, and pass the mode you wish and true on the second parameter
void
setEditable(boolean on)
will enable or disable the Edit. Can be used as a way to make sure the user don't modify something that was already saved on server and can't be modified without proper authorization
String
getText( )
Returns the text within the Edit, without care for the mask. It's important to note that in the case where there is mask, the characters from the mask will come with the user input, to get only the user input you should be using the getTextWithoutMask() method to recover the text
void
setMaxLength()
Is used to limit the characters number the user can digit on the text field
void
setPrediction(boolean prediction)
Is used to set if there should or not exist prediction on this Edit, it is, however set to true by default.