J2ME Polish
J2ME Polish 2.4 Documentation
Enough Software

ChoiceTextField

A ChoiceTextField allows the user to enter data and then shows a selection of matching items from which the user can choose.

Design

A ChoiceTextField
The above design has been realized with these CSS settings:


.addressInput {
	text-wrap: false;
	padding: 3;
	padding-left: 5;
	padding-vertical: 1;
	include-label: true;
	choicetextfield-choicestyle: .addressChoice;
	choicetextfield-containerstyle: .addressChoicesContainer;
	layout: left | expand;
	background {
		type: round-rect;
		color: silver;
	}
}

.addressInput:hover {
	padding: 3;
	padding-left: 3;
	background {
		type: round-rect;
		color: white;
	}
	layout: left | expand;	
}

.addressChoice {
	padding: 2;
	font-size: small;
	font-style: plain;
	font-color: gray;
	layout: left | expand;
}

.addressChoice:hover {
	padding: 2;
	font-size: small;
	font-style: plain;
	font-color: red;
	layout: left | expand;
}

.addressChoicesContainer {
	background-color: argb( 210, 255, 255, 255 );
	layout: left | expand;
}

Use following CSS attributes for designing your ChoiceTextField:

Programming

You can configure the ChoiceTextField in various ways to your needs using the constructor:

public ChoiceTextField(String label, String text, int maxSize, int constraints, 
String[] availableChoices, boolean allowFreeTextEntry, boolean appendChoice, String appendChoiceDelimiter)

The first part of the constructor is the same as for TextFields, in the second part you use following parameters:

  • String[] availableChoices: a list of available texts for the user
  • boolean allowFreeTextEntry: true when the user should be allowed to enter any text that does not match any existing choice
  • boolean appendChoice: true when the selected choices should be appended to the text rather than replacing the text
  • String appendChoiceDelimiter: the character that separates several selections, e.g. '\n' or ';'

You can also specify a character that opens the available choices automatically when it is entered. In the following example we ease the entering of an email address by opening a list of commonly used mail domains after the user enters an '@':

String[] mailServices = = new String[] { "google.com", "yahoo.com", "msn.com", "somewhere.com" };
boolean allowFreeText = false;
boolean appendSelectedChoice = true;
String appendDelimiter = ";";
//#style addressInput
this.receiver = new ChoiceTextField( "to: " , null, 255, TextField.EMAILADDR, 
	mailServices, allowFreeText, appendSelectedChoice, appendDelimiter );
char choiceTriggerChar = '@';
boolean allowChoicesBeforeChoiceTriggerHasBeenEntered = false;
this.receiver.setChoiceTrigger( choiceTriggerChar, allowChoicesBeforeChoiceTriggerHasBeenEntered );

Please refer to the "mail" sample application for a working example.

Configuration

Using the ChoiceTextField makes only sense when you have enabled the direct input mode for TextFields:

<variable name="polish.TextField.useDirectInput" value="true"/>

For other configuration options please refer to the TextFields documentation.

JavaDoc

back to top