Professional Documents
Culture Documents
What is a Widget?
Widget: ImageView
Widget: CheckedTextView
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
3
Widgets: some examples …
TextView
EditText
Button
ToggleButton
CheckBox
Spinner
DatePicker
Custom Views
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
4
Widgets: Java and XML code
XML
< TextView
android:id="@+id/name1"
android:layout_width="match_parent"
android:layout_height="wrap_content” />
JAVA
public TextView text;
text=(TextView)findViewById(R.id.name1);
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
5
Widgets: Hierarchy of the classes …
View
TextView ImageView
AutoCompleteTextVie
CompoundButton
w
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
6
Widgets: TextView
Some methods:
void setText(CharSequence text)
CharSequence getText();
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
7
Widgets: Linkify elements
TextUtils.TruncateAt.END
TextUtils.TruncateAt.MARQUEE
TextUtils.TruncateAt.MIDDLE
TextUtils.TruncateAt.START
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
9
Widgets: EditText
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
10
Widgets: AutocompleteTextView
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
11
Widgets: AutocompleteTextView
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
12
Widgets: Button and CompoundButton
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
13
Widgets: Button and CompoundButton
checkBox CompoundButton
Listener:
onCheckedChangeListener
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
14
Widgets: Button and CompoundButton
radioButton CompoundButton
Listener:
OnCheckedChangeListener
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
15
Widgets: Button and CompoundButton
toggleButton CompoundButton
Listener:
OnCheckedChangeListener
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
16
Widgets: ImageView
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
17
Widgets: CheckedTextView
Methods:
void setChoiceMode(int choiceMode)
long[] getCheckItemIds()
int getCheckedItemPosition()
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
18
Widgets: Other elements …
AnalogClock Widget
DigitalClock Widget
DataPicker Widget
…. … …
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
19
Views and Events
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
20
Views and Events
1.Events Handlers.
Some Views have callback methods to handle specific events.
when a Button is touched onTouchEvent() called
Es.
boolean onKeyDown(int keycode, KeyEvent event)
boolean onKeyUp(int keycode, KeyEvent event)
boolean onKeyMultiple (int keycode, KeyEvent event)
….
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
21
Views and Events
1.Events Handlers.
Some views have callback methods to handle specific events.
when a Button is touched onTouchEvent() called
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
22
Views and Events
1.Events Listeners.
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
23
Views and Events: ActionListener
Some ActionListeners:
OnClickListener
method: onClick()
OnLongClickListener
method: onLongClick()
OnFocusChangeListener
method: onFocusChange()
OnKeyListener
method: onKey()
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
24
Views and Events: ActionListener
More ActionListener:
OnCheckedChangeListener
method: onCheckedChanged()
OnTouchListener
method: onTouch()
OnCreateContextMenuListener
method: onCreateContextMenu()
Luca Bedogni, Marco Di Felice - Programming with Android (c) Luca Bedogni 2012
– Resources
25
Views and Events: ActionListener