Creating the User Input Interface

The most common input type is the EditText view, used for free-form text entry. Using an EditText view, you can provide an onscreen keyboard or let the user choose the physical keyboard (if the device provides one) to enter input.

remember.eps In case you’re familiar with other programming platforms, a text box performs the same function as an EditText view.

Creating an EditText view

In Chapter 9, you created a view layout XML file, named reminder_edit.xml, that contained these lines of code:

<EditText android:id=”@+id/title”

android:layout_width=”fill_parent”

android:layout_height=”wrap_content” />

The snippet creates an input mechanism on the screen where the user can type a task title. The EditText view spans the width of the screen and occupies only as much height as it needs. When the view is selected, Android automatically opens the onscreen keyboard to allow user input.

The previous example takes a minimalistic approach, compared to the following EditText example, which is also present in the reminder_edit.xml layout file:

<EditText android:id=”@+id/body” android:layout_width=”fill_parent”

android:layout_height=”wrap_content”

android:minLines=”5”

android:scrollbars=”vertical”

android:gravity=”top” />

This code creates the body description text of the task. The layout width and height are the same as in the EditText view in the previous example, ...

Get Android Application Development For Dummies, 2nd Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.