Advertisements

Aatul Palandurkar

Taking text input in Android via EditText

Posted on: August 13, 2013

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.


<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>

Multiline Input in Android

If you need, you can use the same <EditText> to take multiline input as per the code snippet given below :

<EditText
 android:id="@+id/editText1"
 android:layout_width="fill_parent"
 android:layout_height="wrap_content"
 android:inputType="textMultiLine"
 android:lines="5" />

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.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Advertisements

Enter your email address to subscribe to this blog and receive notifications of new posts by email.

Join 8,909 other followers

Tweets

YouTube

%d bloggers like this: