Created
February 15, 2016 11:37
-
-
Save codenameone/fb63dd5d6efdb95932be to your computer and use it in GitHub Desktop.
Sample of using the TextField/TextArea API in Codename One to accept user input
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
TableLayout tl; | |
int spanButton = 2; | |
if(Display.getInstance().isTablet()) { | |
tl = new TableLayout(7, 2); | |
} else { | |
tl = new TableLayout(14, 1); | |
spanButton = 1; | |
} | |
tl.setGrowHorizontally(true); | |
hi.setLayout(tl); | |
TextField firstName = new TextField("", "First Name", 20, TextArea.ANY); | |
TextField surname = new TextField("", "Surname", 20, TextArea.ANY); | |
TextField email = new TextField("", "E-Mail", 20, TextArea.EMAILADDR); | |
TextField url = new TextField("", "URL", 20, TextArea.URL); | |
TextField phone = new TextField("", "Phone", 20, TextArea.PHONENUMBER); | |
TextField num1 = new TextField("", "1234", 4, TextArea.NUMERIC); | |
TextField num2 = new TextField("", "1234", 4, TextArea.NUMERIC); | |
TextField num3 = new TextField("", "1234", 4, TextArea.NUMERIC); | |
TextField num4 = new TextField("", "1234", 4, TextArea.NUMERIC); | |
Button submit = new Button("Submit"); | |
TableLayout.Constraint cn = tl.createConstraint(); | |
cn.setHorizontalSpan(spanButton); | |
cn.setHorizontalAlign(Component.RIGHT); | |
hi.add("First Name").add(firstName). | |
add("Surname").add(surname). | |
add("E-Mail").add(email). | |
add("URL").add(url). | |
add("Phone").add(phone). | |
add("Credit Card"). | |
add(GridLayout.encloseIn(4, num1, num2, num3, num4)). | |
add(cn, submit); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Sample usage of TextField.
Notice that all usage of TextField in this code can be replaced with TextArea.
From the Codename One project