Translate To Your Own Langauge

TextView & EditText

In this tutorial, I will explain the concept of EditText and TextView controls provided in Android. If you are new to android then see Getting Started with Android.
  • EditText is used to get value from user (Input control).
  • TextView is used to display value on the screen (Output control).
From the above two lines, now you have a rough idea about what these controls are. So now i will use an example where these two controls can be used. See the output bellow.

Make following .xml file


 <RelativeLayout xmlns:android="http://schemas.android.com/apk/res/android"
    xmlns:tools="http://schemas.android.com/tools"
    android:layout_width="match_parent"
    android:layout_height="match_parent"
    android:paddingBottom="@dimen/activity_vertical_margin"
    android:paddingLeft="@dimen/activity_horizontal_margin"
    android:paddingRight="@dimen/activity_horizontal_margin"
    android:paddingTop="@dimen/activity_vertical_margin"
    tools:context=".MainActivity" >

    <TextView
        android:id="@+id/textView1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignParentLeft="true"
        android:layout_alignParentTop="true"
        android:layout_marginTop="39dp"
        android:text="@string/username"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <TextView
        android:id="@+id/textView2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignRight="@+id/textView1"
        android:layout_below="@+id/textView1"
        android:layout_marginTop="32dp"
        android:text="@string/password"
        android:textAppearance="?android:attr/textAppearanceLarge" />

    <EditText
        android:id="@+id/editText1"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignTop="@+id/textView1"
        android:layout_marginLeft="38dp"
        android:layout_toRightOf="@+id/textView1"
        android:ems="10" >

        <requestFocus />
    </EditText>

    <EditText
        android:id="@+id/editText2"
        android:layout_width="wrap_content"
        android:layout_height="wrap_content"
        android:layout_alignBaseline="@+id/textView2"
        android:layout_alignBottom="@+id/textView2"
        android:layout_alignLeft="@+id/editText1"
        android:ems="10"
        android:inputType="textPassword" />

</RelativeLayout>

Now your Interface is ready. You can run the app on your device or on virtual device.
If you don't know how to make virtual device then click here.

0 Responses to “TextView & EditText”

Post a Comment

Comment your feedback for the post. You can also ask your queries regarding android.

Blogger Widgets
All Rights Reserved Android Tutorials | Designed by: Deepak Anand