Android Programming
Lecture 5
9/16/2011
RadioButtons
Multiple RadioButtons
belong in a RadioGroup
RadioGroup
Manages only-one-
selected
Exposes functions to:
programmatically select a
button via ID
determine ID of button
currently selected
RadioButtons
This is not explicitly using the Listener pattern
for the RadioButtons (not responding to the
click; just checking what is clicked)
RadioButtons
Can also listen directly
to clicks on
RadioButtons
Spinner
Drop-down selection box, with a list of
RadioButton options
Provides screen real-estate savings over multiple
individual RadioButtons
Requires a different approach to setup
An array of choices to present
An ArrayAdapter to format the array data for the
Spinner
The actual Spinner view component, associated with
the ArrayAdapter
Spinner
Spinner
Setup prompt at top of pop-up that appears
Set up array
Associate adapter with array
and spinner with adapter
Spinner: Listening for Selection Events
in Spinner
Spinner: Listening for Selection Events
in Spinner
Wait a Minute!
Set up array
Isnt this dealing with
setting up the interface, in the code?
Can I make this an XML resource too?
CheckBox
2-state toggles (on/off)
Not organized in a group
Some, all, or none can be checked in a logical
group
Generates Click events
A Click event only says a click happened: Need to
be able to check state of CheckBox
Call boolean isChecked() method on CheckBox
CheckBox
EditText
Allows entry of arbitrary text from physical or
virtual keyboard
Typically end of entry is signified by
Associated button being clicked OR (a Click event)
Return being pressed in the editable field (a
KeyPress event)
Can constrain to only certain types of input
EditText
EditText
Edit Text: Constraining Type
Even more: developer.android.com/reference/android/text/InputType.html
EditText: Constraining Type
Password type -> hides
each letter after it is typed
SeekBar
SeekBar (slider) allow
selection of integer
values using a natural
interface
Constraints:
Min: 0
Max: settable
Changes by: 1
Starting point for knob
can be set
Senses initiation of
touch ,ending of touch,
and movement
SeekBar
SeekBar