Pick and Choose
With limited‑input devices like phones, having widgets and dialogs that are aware of the type of stuff somebody is supposed to be entering is very helpful. It minimizes keystrokes and screen taps, plus reduces the chance of making some sort of error (e.g., entering a letter someplace where only numbers are expected).
As previously shown, has content‑aware flavors for entering in numbers, phone numbers, etc. Android also supports widgets (, ) and dialogs (, ) for helping users enter dates and times.
The and allow you to set the starting date for the selection, in the form of a year, month, and day of month value. Note that the month runs from 0 for January through 11 for December. Most importantly, each let you provide a callback object ( or ) where you are informed of a new date selected by the user. It is up to you to store that date someplace, particularly if you are using the dialog, since there is no other way for you to get at the chosen date later on.
Similarly, and let you:
• set the initial time the user can adjust, in the form of an hour (0 through 23) and a minute (0 through 59)
• indicate if the selection should be in 12‑hour mode with an AM/PM toggle, or in 24‑hour mode (what in the US is thought of as “military time” and in the rest of the world is thought of as “the way times are supposed to be”)
• provide a callback object ( or ) to be notified of when the user has chosen a new time, which is supplied to you in the form of an hour and minute
The sample project, found along with all other code samples in this chapter in the Source Code area of http://apress.com, shows a trivial layout containing a label and two buttons – the buttons will pop up the dialog flavors of the date and time pickers:
The more interesting stuff comes in the Java source:
Дата добавления: 2015-05-16; просмотров: 671;