Arten von Textfeldern


Es wird immer die passende Tastatur am Display angezeigt und falsche Eingaben gesperrt

NameDescripton
PlainTextEinfacher Text
PasswordMaskierter Text
Password(Numeric)Maskierte Zahlen
E-MailEmail Adresse
PhoneTelefonnummer
Postal AddressPostalische Adresse
MultilineTextMehrzeiliger Text
TimeZeit
DateDatum
NumberPositive Ganzzahlen
Number(Signed)Alle Ganzzahlen
Number(Decimal)Kommazahlen

Eigenschaften


Autokorrektur Aktivieren:

<EditText
	android:inputType="textCapSentences|textAutoCorrect"
/>

Passwort im Passwortfeld anzeigen

<EditText
	android:inputType="TYPE_CLASS_TEXT|TYPE_TEXT_VARIATION_VISIBLE_PASSWORD"
/>

Mehrzeiliges Adressfeld mit automatisch großen Wörtern

<EditText
	android:inputType="TYPE_CLASS_TEXT|TYPE_TEXT_VARIATION_POSTAL_ADDRESS
						|TYPE_TEXT_FLAG_MULTI_LINE"
/>

Zeit Eingabe

<EditText
	android:inputType="TYPE_CLASS_DATETIME | TYPE_DATETIME_VARIATION_TIME"
/>

Bestätigungstaste


Um ein passendes Icon anzuzeigen:

<EditText 
	android:inputType="text" 
	android:imeOptions="actionNext|actionDone|actionGo|actionSearch|actionSend|uvm." 
/>

Hiermit wird OnEditorAction ausgelöst. Darauf reagieren kann man folgendermaßen:

EditText editText = (EditText) findViewById(R.id.search); editText.setOnEditorActionListener(new TextView.OnEditorActionListener() { 
	@Override 
	public boolean onEditorAction(TextView v, int actionId, KeyEvent event) { 
		boolean handled = false; 
		if (actionId == EditorInfo.IME_ACTION_NEXT) { 
			sendMessage(); 
			handled = true; 
		} 
		return handled; 
	} 
});

Autovervollständigung


activity.xml

<AutoCompleteTextView
	android:id="@+id/txtInputTree"
	...
	android:text="AutoCompleteTextView"
/>

/res/values/strings.xml

<resources>
	<string-array name="trees">
		<item>Ahorn</item>
		...
		<item>Zeder</item>
	</string-array>
</resources>

xxx.java

AutoCompleteTextView txtInputTree; 
txtInputTree = (AutoCompleteTextView) findViewById(R.id.txtInputTree); 
String[] trees = getResources().getStringArray(R.array.trees); 
ArrayAdapter adapter = new ArrayAdapter(this, android.R.layout.simple_list_item_1,trees); 
txtInputTree.setAdapter(adapter);