Chapter 12

Handling User Input

In This Chapter

arrow Working with EditText views

arrow Creating date pickers and time pickers

arrow Setting up alert dialogs

arrow Validating user input

Rarely does an application not allow users to interact with it. Whether they use text, a date or time picker, a radio button, a check box, or any other input mechanism, users need to interact with your application in one way or another. This chapter focuses solely on user input in the form of alert confirmation, free‐form text, and dates and times.

Creating the User Input Interface

The most common input type is the EditText view, used for free‐form text entry. With 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.

Creating an EditText view

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

<EditText     android:id="@+id/title"     android:layout_width="match_parent"     android:layout_height="wrap_content"     . . .     android:hint="@string/title"/> ...

Get Android App Development For Dummies, 3rd Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.