Implementing an Edit Text View

You need to add a View to your Activity that will let the user input some text. You will then parse that text and send it to the Intent call from the previous section. Because all Views inherit from the base View, they are helpfully similar in structure and usage. You will find that implementing an EditText is a very simple operation.

First, lay out the Views in your main.xml. You will actually add two Views here: a TextView to act as a label and give some direction to the user, and an EditText to accept the user's input. Together these two Views will add the needed depth and practicality to your Activity.

As you form the look of your Activity, keep in mind that the .xml file is formed visually. This means that if you want the TextView to appear above the EditText on the finished Activity, you should place it before the EditText in main.xml.

Because you have used TextViews a few times now, creation of this View will not get too involved. Simply take a look at the attributes that you set in your TextView:

<TextView android:id="@+id/textLabel"



android:text="Enter Number to Dial:"

There is nothing out of the ordinary here. This is just a simple TextView with the text Enter Number to Dial:. This TextView will serve as a label for your EditView. Here's how you set the attributes for the EditView.

<EditText android:id="@+id/phoneNumber" android:layout_width="fill_parent"


0 0

Post a comment