Objectives :
- How to take input in Android?
- How to take text input in Android?
- How to use EditText in Android?
- How to take multiline input in Android?
If you wish to take text input in Android, you can use <EditText> to take the text input in Android.
Here is the small example showing different uses of EditText. EditText can be also used to take multiline input as that of textarea.
[sourcecode language=”xml”]
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:tools="http://schemas.android.com/tools"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="First Name" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="text"
android:id="@+id/EditTextFirstName"
android:hint="First Name" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Cell No" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="number"
android:hint="Cell No." />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Email ID" />
<EditText
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textEmailAddress"
android:hint="Email Name" />
<TextView
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:text="Message" />
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="5" />
</LinearLayout>
[/sourcecode]
Multiline Input in Android
If you need, you can use the same <EditText> to take multiline input as per the code snippet given below :
[sourcecode language=”xml”]
<EditText
android:id="@+id/editText1"
android:layout_width="fill_parent"
android:layout_height="wrap_content"
android:inputType="textMultiLine"
android:lines="5" />
[/sourcecode]
Here, android:inputType=”textMultiLine” will convert the single line text input into multi line input and android:lines=”5″ will give 5 (five) visible lines input.