Difference between revisions of "Android Studio: Input Text"
Onnowpurbo (talk | contribs) (Created page with "Overview The EditText is the standard text entry widget in Android apps. If the user needs to enter text into an app, this is the primary way for them to do that. EditText T...") |
Onnowpurbo (talk | contribs) |
||
Line 1: | Line 1: | ||
− | Overview | + | ==Overview== |
+ | |||
The EditText is the standard text entry widget in Android apps. If the user needs to enter text into an app, this is the primary way for them to do that. | The EditText is the standard text entry widget in Android apps. If the user needs to enter text into an app, this is the primary way for them to do that. | ||
− | EditText | + | ==EditText== |
There are many important properties that can be set to customize the behavior of an EditText. Several of these are listed below. Check out the official text fields guide for even more input field details. | There are many important properties that can be set to customize the behavior of an EditText. Several of these are listed below. Check out the official text fields guide for even more input field details. | ||
− | Usage | + | ==Usage== |
+ | |||
An EditText is added to a layout with all default behaviors with the following XML: | An EditText is added to a layout with all default behaviors with the following XML: | ||
Line 17: | Line 19: | ||
Note that an EditText is simply a thin extension of the TextView and inherits all of the same properties. | Note that an EditText is simply a thin extension of the TextView and inherits all of the same properties. | ||
− | Retrieving the Value | + | ==Retrieving the Value== |
+ | |||
Getting the value of the text entered into an EditText is as follows: | Getting the value of the text entered into an EditText is as follows: | ||
Line 23: | Line 26: | ||
String strValue = simpleEditText.getText().toString(); | String strValue = simpleEditText.getText().toString(); | ||
− | Customizing the Input Type | + | ==Customizing the Input Type== |
By default, any text contents within an EditText control is displayed as plain text. By setting inputType, we can facilitate input of different types of information, like phone numbers and passwords: | By default, any text contents within an EditText control is displayed as plain text. By setting inputType, we can facilitate input of different types of information, like phone numbers and passwords: |
Latest revision as of 14:40, 13 April 2022
Overview
The EditText is the standard text entry widget in Android apps. If the user needs to enter text into an app, this is the primary way for them to do that.
EditText
There are many important properties that can be set to customize the behavior of an EditText. Several of these are listed below. Check out the official text fields guide for even more input field details.
Usage
An EditText is added to a layout with all default behaviors with the following XML:
<EditText android:id="@+id/et_simple" android:layout_height="wrap_content" android:layout_width="match_parent"> </EditText>
Note that an EditText is simply a thin extension of the TextView and inherits all of the same properties.
Retrieving the Value
Getting the value of the text entered into an EditText is as follows:
EditText simpleEditText = (EditText) findViewById(R.id.et_simple); String strValue = simpleEditText.getText().toString();
Customizing the Input Type
By default, any text contents within an EditText control is displayed as plain text. By setting inputType, we can facilitate input of different types of information, like phone numbers and passwords:
<EditText ... android:inputType="phone"> </EditText>