SlideShare a Scribd company logo
3
 Widget & UI
 Anuchit Chalothorn
 anoochit@gmail.com

Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
Widget
Widget has properties, you can use activity
design to config the properties or use layout
editor to edit XML document.
Android App Development 03 : Widget & UI
Android App Development 03 : Widget & UI
Text View
XML Attribute
  ● android:textColor="#33333"
  ● android:text="Hello World"
  ● android:textSize="30sp"
Methods
  ● setText
  ● setTypeFace


Ref: http://developer.android.com/reference/android/widget/TextView.html
Edit Text
XML Attribute
  ● android:inputType="text"
Methods
  ● getText
  ● setText




Ref: http://developer.android.com/reference/android/widget/EditText.html
Edit Text inputType
●     text                                                 ●     number
●     textPersonName                                       ●     numberSigned
●     textPassword                                         ●     numberDecimal
●     numberPassword                                       ●     AutoCompleteTextView
●     textEmailAddress                                     ●     MultiAutoCompleteTextView
●     phone
●     textPostalAddress
●     textMultiLine
●     time
●     date



Ref: http://developer.android.com/guide/topics/ui/controls/text.html
Buttons
XML Attribute
      ● android:style="?android:attr/buttonStyleSmall"
      ● android:text="Button"
Methods
  ● setOnClickListener




Ref: http://developer.android.com/reference/android/widget/Button.html
Checkboxes
Methods
  ● isChecked
  ● setChecked(true)
  ● setOnClickListener




Ref: http://developer.android.com/reference/android/widget/CheckBox.html
Radio Buttons
Use with RadioGroup Layout
Methods
  ● isChecked
  ● toggle
  ● setOnClickListener




Ref: http://developer.android.com/guide/topics/ui/controls/radiobutton.html
Toggle Buttons
XML Attribute
  ● android:textOn="Vibrate on"
  ● android:textOff="Vibrate off"
Methods
  ● setOnCheckedChangeListener




Ref: http://developer.android.com/guide/topics/ui/controls/togglebutton.html
Workshop: Input Form
Create form input for register new user to the
system (fake), use following fields:
  ● Firstname Lastname (Edit Text)
  ● Birthdate (Edit Text, Datepicker)
  ● Gender (Radio Button)
  ● Subscribe (Checkbox)
  ● Email (Edit Text)
  ● Password (Edit Text)
  ● Submit Button (Button)
Android App Development 03 : Widget & UI
Spinner
The choices you provide for the spinner can
come from any source, but must be provided
through an SpinnerAdapter, such as an
ArrayAdapter if the choices are available in an
array or a CursorAdapter if the choices are
available from a database query.




Ref: http://developer.android.com/guide/topics/ui/controls/spinner.html
Spinner
String resource file:
Spinner spinner = (Spinner) findViewById(R.id.spinner);
// Create an ArrayAdapter using the string array and a default
spinner layout
ArrayAdapter<CharSequence> adapter = ArrayAdapter.
createFromResource(this,R.array.services, android.R.layout.
simple_spinner_item);
// Specify the layout to use when the list of choices appears
adapter.setDropDownViewResource(android.R.layout.
simple_spinner_dropdown_item);
// Apply the adapter to the spinner
spinner.setAdapter(adapter);
Spinner
Methods
   ● getSelectedItem
   ● getSelectedItemId
   ● getSelectedItemPosition
Listener
   ● setOnClickListener
   ● setOnItemSelectedListener
Android App Development 03 : Widget &amp; UI
List View
The display of elements in a lists is a very
common pattern in mobile applications. The
user sees a list of items and can scroll through
them.
List View
Listener
   ● setOnItemClickListener
   ● setOnLongClickListener
Android App Development 03 : Widget &amp; UI
Multi Columns List View
Custom layout listview row, use adapter select
data show in custom layout
Android App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UI
Alert Dialog
A dialog that can show a title, up to three
buttons, a list of selectable items, or a custom
layout.




Ref: http://developer.android.com/guide/topics/ui/dialogs.html
Android App Development 03 : Widget &amp; UI
Dialog with Custom Layout
If you want to create your own dialogs, you
create a layout file for the dialog. This layout file
is assigned to the dialog via the
setContentView() method
Android App Development 03 : Widget &amp; UI
Picker
Android provides controls for the user to pick a
time or pick a date as ready-to-use dialogs.
Using these pickers helps ensure that your
users can pick a time or date that is valid,
formatted correctly, and adjusted to the user's
locale.




Ref: http://developer.android.com/guide/topics/ui/controls/pickers.html
Time Picker
In Android, you can use android.widget.
TimePicker class to render a time picker
component to select hour and minute in a pre-
defined user interface, render a dialog box via
android.app.TimePickerDialog
Android App Development 03 : Widget &amp; UI
Date Picker
In Android you can use android.widget.
DatePicker class to render a date picker
component to select day, month and year in a
pre-defined user interface and render dialog
box via android.app.DatePickerDialog.
Android App Development 03 : Widget &amp; UI
ActionBar
The ActionBar is located at the top of the
activity. It can display the activity title, icon,
actions which can be triggered, additional views
Views other interactive items. It can also be
used for navigation in your application.




Ref: http://developer.android.com/guide/topics/ui/actionbar.html
ActionBar in old devices
ActionBar has introduced in Android 3.0, The
ActionBar Sherlock library allow to use the
ActionBar on old devices as Android 1.6
ActionBar : Home Button
The ActionBar shows an icon of your application, this is
called the home icon. If you select this icon the
onOptionsItemSelected() method will be called with the
value android.R.id.home. The recommendation is to
return to the main Activity in your program.

ActionBar actionbar = getActionBar();
actionbar.setHomeButtonEnabled(true);
Android App Development 03 : Widget &amp; UI
Workshop: Navigating Up
Like home button, ActionBar can use as up
navigation or goto parent activity, to enable up
button use setDisplayHomeUpEnabled()
method. You should include
FLAG_ACTIVITY_CLEAR_TOP in the Intent.
Android App Development 03 : Widget &amp; UI
ActionBar: Action View
a custom View can add to ActionBar, use
setCustomView method and enable display of
custom View via setDisplay methods in
ActionBar.DISPLAY_SHOW_CUSTOM flag.
Workshop: Action View
Create an App with ActionBar, has 2 option
menus refresh and setting, after push refresh
menu the show the progress bar.
Android App Development 03 : Widget &amp; UI
ActionBar: Indeterminate progress
ActionBar can show progress bar use
requestWindowsFeature in request to use
interminate progress bar


requestWindowFeature(Window.
FEATURE_INDETERMINATE_PROGRESS);
setProgressBarIndeterminateVisibility(true);
Android App Development 03 : Widget &amp; UI
ActionBar: Dimming navigation
You can also hide the software navigation button in
your Android application to have more space
available. If the user touches the button of the
screen the navigation button are automatically
shown again.
getWindow().
  getDecorView(). setSystemUiVisibility(View.
SYSTEM_UI_FLAG_HIDE_NAVIGATION);
Android App Development 03 : Widget &amp; UI
Notification
Android allows to put notification into the
titlebar of your application. The user can
expand the notification bar and by selecting the
notification the user can trigger another activity.




Ref: http://developer.android.com/guide/topics/ui/notifiers/notifications.html
Notification
To create notifications you use the
NotificationManager class which can be
received from the Context, e.g. an activity or a
service, via the getSystemService() method.

Notification noti = new Notification.Builder(this)
        .setContentTitle("Title")
       .setContentText("Body").build();
Notification

NotificationManager notificationManager =
  (NotificationManager) getSystemService
(NOTIFICATION_SERVICE);

// Hide the notification after its selected
noti.flags |= Notification.FLAG_AUTO_CANCEL;

notificationManager.notify(0, noti);
Workshop: Notification
Create App with a single button, after push
button the notification will appear in the
notification bar and use can cancel notification.
Android App Development 03 : Widget &amp; UI
End
Ad

More Related Content

Viewers also liked (18)

Android App Development 04 : Location API
Android App Development 04 : Location APIAndroid App Development 04 : Location API
Android App Development 04 : Location API
Anuchit Chalothorn
 
Advance ui development and design
Advance ui  development and design Advance ui  development and design
Advance ui development and design
Rakesh Jha
 
Android UI Patterns
Android UI PatternsAndroid UI Patterns
Android UI Patterns
Peter Pascale
 
AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
Ahsanul Karim
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycle
Ahsanul Karim
 
Android UI Reference
Android UI ReferenceAndroid UI Reference
Android UI Reference
GauntFace
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
Android UI Development
Android UI DevelopmentAndroid UI Development
Android UI Development
Jussi Pohjolainen
 
Day 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts APIDay 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts API
Ahsanul Karim
 
Day 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentDay 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver Component
Ahsanul Karim
 
Day 15: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in Background
Ahsanul Karim
 
Android ui layout
Android ui layoutAndroid ui layout
Android ui layout
Krazy Koder
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through Activities
Ahsanul Karim
 
Lecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesLecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & Preferences
Ahsanul Karim
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]
Ahsanul Karim
 
Acrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVMAcrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVM
Dong-Ho Lee
 
Advance Android Layout Walkthrough
Advance Android Layout WalkthroughAdvance Android Layout Walkthrough
Advance Android Layout Walkthrough
Somkiat Khitwongwattana
 
Android ppt
Android pptAndroid ppt
Android ppt
Ansh Singh
 
Android App Development 04 : Location API
Android App Development 04 : Location APIAndroid App Development 04 : Location API
Android App Development 04 : Location API
Anuchit Chalothorn
 
Advance ui development and design
Advance ui  development and design Advance ui  development and design
Advance ui development and design
Rakesh Jha
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycle
Ahsanul Karim
 
Android UI Reference
Android UI ReferenceAndroid UI Reference
Android UI Reference
GauntFace
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
Day 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts APIDay 15: Content Provider: Using Contacts API
Day 15: Content Provider: Using Contacts API
Ahsanul Karim
 
Day 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentDay 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver Component
Ahsanul Karim
 
Day 15: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in Background
Ahsanul Karim
 
Android ui layout
Android ui layoutAndroid ui layout
Android ui layout
Krazy Koder
 
Day 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through ActivitiesDay 4: Android: Getting Active through Activities
Day 4: Android: Getting Active through Activities
Ahsanul Karim
 
Lecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & PreferencesLecture 5: Storage: Saving Data Database, Files & Preferences
Lecture 5: Storage: Saving Data Database, Files & Preferences
Ahsanul Karim
 
Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]Day 5: Android User Interface [View Widgets]
Day 5: Android User Interface [View Widgets]
Ahsanul Karim
 
Acrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVMAcrhitecture deisign pattern_MVC_MVP_MVVM
Acrhitecture deisign pattern_MVC_MVP_MVVM
Dong-Ho Lee
 

Similar to Android App Development 03 : Widget &amp; UI (20)

Android programming basics
Android programming basicsAndroid programming basics
Android programming basics
Egerton University
 
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & SpinnerAndroid User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
Ahsanul Karim
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
Shrijan Tiwari
 
Android Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompatAndroid Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompat
cbeyls
 
UI controls in Android
UI controls in Android UI controls in Android
UI controls in Android
DivyaKS12
 
01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgets
Siva Kumar reddy Vasipally
 
Android UI
Android UIAndroid UI
Android UI
nationalmobileapps
 
21 android2 updated
21 android2 updated21 android2 updated
21 android2 updated
GhanaGTUG
 
Android
AndroidAndroid
Android
San Bunna
 
The Action Bar: Front to Back
The Action Bar: Front to BackThe Action Bar: Front to Back
The Action Bar: Front to Back
CommonsWare
 
Android session 3
Android session 3Android session 3
Android session 3
Ahesanali Suthar
 
viWave Study Group - Introduction to Google Android Development - Chapter 23 ...
viWave Study Group - Introduction to Google Android Development - Chapter 23 ...viWave Study Group - Introduction to Google Android Development - Chapter 23 ...
viWave Study Group - Introduction to Google Android Development - Chapter 23 ...
Ted Chien
 
Android App Development - 04 Views and layouts
Android App Development - 04 Views and layoutsAndroid App Development - 04 Views and layouts
Android App Development - 04 Views and layouts
Diego Grancini
 
Curso Básico Android
Curso Básico AndroidCurso Básico Android
Curso Básico Android
Eduardo Lagares
 
Android training day 2
Android training day 2Android training day 2
Android training day 2
Vivek Bhusal
 
Implementing cast in android
Implementing cast in androidImplementing cast in android
Implementing cast in android
Angelo Rüggeberg
 
Application Development - Overview on Android OS
Application Development - Overview on Android OSApplication Development - Overview on Android OS
Application Development - Overview on Android OS
Pankaj Maheshwari
 
Android Tutorial
Android TutorialAndroid Tutorial
Android Tutorial
Fun2Do Labs
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
Utkarsh Mankad
 
Desenvolver para Chromecast
Desenvolver para ChromecastDesenvolver para Chromecast
Desenvolver para Chromecast
Pedro Veloso
 
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & SpinnerAndroid User Interface Tutorial: DatePicker, TimePicker & Spinner
Android User Interface Tutorial: DatePicker, TimePicker & Spinner
Ahsanul Karim
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
Shrijan Tiwari
 
Android Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompatAndroid Support Library: Using ActionBarCompat
Android Support Library: Using ActionBarCompat
cbeyls
 
UI controls in Android
UI controls in Android UI controls in Android
UI controls in Android
DivyaKS12
 
01 09 - graphical user interface - basic widgets
01  09 - graphical user interface - basic widgets01  09 - graphical user interface - basic widgets
01 09 - graphical user interface - basic widgets
Siva Kumar reddy Vasipally
 
21 android2 updated
21 android2 updated21 android2 updated
21 android2 updated
GhanaGTUG
 
The Action Bar: Front to Back
The Action Bar: Front to BackThe Action Bar: Front to Back
The Action Bar: Front to Back
CommonsWare
 
viWave Study Group - Introduction to Google Android Development - Chapter 23 ...
viWave Study Group - Introduction to Google Android Development - Chapter 23 ...viWave Study Group - Introduction to Google Android Development - Chapter 23 ...
viWave Study Group - Introduction to Google Android Development - Chapter 23 ...
Ted Chien
 
Android App Development - 04 Views and layouts
Android App Development - 04 Views and layoutsAndroid App Development - 04 Views and layouts
Android App Development - 04 Views and layouts
Diego Grancini
 
Android training day 2
Android training day 2Android training day 2
Android training day 2
Vivek Bhusal
 
Implementing cast in android
Implementing cast in androidImplementing cast in android
Implementing cast in android
Angelo Rüggeberg
 
Application Development - Overview on Android OS
Application Development - Overview on Android OSApplication Development - Overview on Android OS
Application Development - Overview on Android OS
Pankaj Maheshwari
 
Android Tutorial
Android TutorialAndroid Tutorial
Android Tutorial
Fun2Do Labs
 
Android activity, service, and broadcast recievers
Android activity, service, and broadcast recieversAndroid activity, service, and broadcast recievers
Android activity, service, and broadcast recievers
Utkarsh Mankad
 
Desenvolver para Chromecast
Desenvolver para ChromecastDesenvolver para Chromecast
Desenvolver para Chromecast
Pedro Veloso
 
Ad

More from Anuchit Chalothorn (20)

Flutter Workshop 2021 @ ARU
Flutter Workshop 2021 @ ARUFlutter Workshop 2021 @ ARU
Flutter Workshop 2021 @ ARU
Anuchit Chalothorn
 
Flutter workshop @ bang saen 2020
Flutter workshop @ bang saen 2020Flutter workshop @ bang saen 2020
Flutter workshop @ bang saen 2020
Anuchit Chalothorn
 
13 web service integration
13 web service integration13 web service integration
13 web service integration
Anuchit Chalothorn
 
09 material design
09 material design09 material design
09 material design
Anuchit Chalothorn
 
07 intent
07 intent07 intent
07 intent
Anuchit Chalothorn
 
05 binding and action
05 binding and action05 binding and action
05 binding and action
Anuchit Chalothorn
 
04 layout design and basic widget
04 layout design and basic widget04 layout design and basic widget
04 layout design and basic widget
Anuchit Chalothorn
 
03 activity life cycle
03 activity life cycle03 activity life cycle
03 activity life cycle
Anuchit Chalothorn
 
02 create your first app
02 create your first app02 create your first app
02 create your first app
Anuchit Chalothorn
 
01 introduction
01 introduction 01 introduction
01 introduction
Anuchit Chalothorn
 
Material Theme
Material ThemeMaterial Theme
Material Theme
Anuchit Chalothorn
 
00 Android Wear Setup Emulator
00 Android Wear Setup Emulator00 Android Wear Setup Emulator
00 Android Wear Setup Emulator
Anuchit Chalothorn
 
MongoDB Replication Cluster
MongoDB Replication ClusterMongoDB Replication Cluster
MongoDB Replication Cluster
Anuchit Chalothorn
 
MongoDB Shard Cluster
MongoDB Shard ClusterMongoDB Shard Cluster
MongoDB Shard Cluster
Anuchit Chalothorn
 
IT Automation with Chef
IT Automation with ChefIT Automation with Chef
IT Automation with Chef
Anuchit Chalothorn
 
IT Automation with Puppet Enterprise
IT Automation with Puppet EnterpriseIT Automation with Puppet Enterprise
IT Automation with Puppet Enterprise
Anuchit Chalothorn
 
Using PhoneGap Command Line
Using PhoneGap Command LineUsing PhoneGap Command Line
Using PhoneGap Command Line
Anuchit Chalothorn
 
Collaborative development with Git | Workshop
Collaborative development with Git | WorkshopCollaborative development with Git | Workshop
Collaborative development with Git | Workshop
Anuchit Chalothorn
 
OpenStack Cheat Sheet V2
OpenStack Cheat Sheet V2OpenStack Cheat Sheet V2
OpenStack Cheat Sheet V2
Anuchit Chalothorn
 
REST API with CakePHP
REST API with CakePHPREST API with CakePHP
REST API with CakePHP
Anuchit Chalothorn
 
Ad

Android App Development 03 : Widget &amp; UI

  • 1. 3 Widget & UI Anuchit Chalothorn [email protected] Licensed under a Creative Commons Attribution-NonCommercial-ShareAlike 3.0 Unported License.
  • 2. Widget Widget has properties, you can use activity design to config the properties or use layout editor to edit XML document.
  • 5. Text View XML Attribute ● android:textColor="#33333" ● android:text="Hello World" ● android:textSize="30sp" Methods ● setText ● setTypeFace Ref: http://developer.android.com/reference/android/widget/TextView.html
  • 6. Edit Text XML Attribute ● android:inputType="text" Methods ● getText ● setText Ref: http://developer.android.com/reference/android/widget/EditText.html
  • 7. Edit Text inputType ● text ● number ● textPersonName ● numberSigned ● textPassword ● numberDecimal ● numberPassword ● AutoCompleteTextView ● textEmailAddress ● MultiAutoCompleteTextView ● phone ● textPostalAddress ● textMultiLine ● time ● date Ref: http://developer.android.com/guide/topics/ui/controls/text.html
  • 8. Buttons XML Attribute ● android:style="?android:attr/buttonStyleSmall" ● android:text="Button" Methods ● setOnClickListener Ref: http://developer.android.com/reference/android/widget/Button.html
  • 9. Checkboxes Methods ● isChecked ● setChecked(true) ● setOnClickListener Ref: http://developer.android.com/reference/android/widget/CheckBox.html
  • 10. Radio Buttons Use with RadioGroup Layout Methods ● isChecked ● toggle ● setOnClickListener Ref: http://developer.android.com/guide/topics/ui/controls/radiobutton.html
  • 11. Toggle Buttons XML Attribute ● android:textOn="Vibrate on" ● android:textOff="Vibrate off" Methods ● setOnCheckedChangeListener Ref: http://developer.android.com/guide/topics/ui/controls/togglebutton.html
  • 12. Workshop: Input Form Create form input for register new user to the system (fake), use following fields: ● Firstname Lastname (Edit Text) ● Birthdate (Edit Text, Datepicker) ● Gender (Radio Button) ● Subscribe (Checkbox) ● Email (Edit Text) ● Password (Edit Text) ● Submit Button (Button)
  • 14. Spinner The choices you provide for the spinner can come from any source, but must be provided through an SpinnerAdapter, such as an ArrayAdapter if the choices are available in an array or a CursorAdapter if the choices are available from a database query. Ref: http://developer.android.com/guide/topics/ui/controls/spinner.html
  • 15. Spinner String resource file: Spinner spinner = (Spinner) findViewById(R.id.spinner); // Create an ArrayAdapter using the string array and a default spinner layout ArrayAdapter<CharSequence> adapter = ArrayAdapter. createFromResource(this,R.array.services, android.R.layout. simple_spinner_item); // Specify the layout to use when the list of choices appears adapter.setDropDownViewResource(android.R.layout. simple_spinner_dropdown_item); // Apply the adapter to the spinner spinner.setAdapter(adapter);
  • 16. Spinner Methods ● getSelectedItem ● getSelectedItemId ● getSelectedItemPosition Listener ● setOnClickListener ● setOnItemSelectedListener
  • 18. List View The display of elements in a lists is a very common pattern in mobile applications. The user sees a list of items and can scroll through them.
  • 19. List View Listener ● setOnItemClickListener ● setOnLongClickListener
  • 21. Multi Columns List View Custom layout listview row, use adapter select data show in custom layout
  • 24. Alert Dialog A dialog that can show a title, up to three buttons, a list of selectable items, or a custom layout. Ref: http://developer.android.com/guide/topics/ui/dialogs.html
  • 26. Dialog with Custom Layout If you want to create your own dialogs, you create a layout file for the dialog. This layout file is assigned to the dialog via the setContentView() method
  • 28. Picker Android provides controls for the user to pick a time or pick a date as ready-to-use dialogs. Using these pickers helps ensure that your users can pick a time or date that is valid, formatted correctly, and adjusted to the user's locale. Ref: http://developer.android.com/guide/topics/ui/controls/pickers.html
  • 29. Time Picker In Android, you can use android.widget. TimePicker class to render a time picker component to select hour and minute in a pre- defined user interface, render a dialog box via android.app.TimePickerDialog
  • 31. Date Picker In Android you can use android.widget. DatePicker class to render a date picker component to select day, month and year in a pre-defined user interface and render dialog box via android.app.DatePickerDialog.
  • 33. ActionBar The ActionBar is located at the top of the activity. It can display the activity title, icon, actions which can be triggered, additional views Views other interactive items. It can also be used for navigation in your application. Ref: http://developer.android.com/guide/topics/ui/actionbar.html
  • 34. ActionBar in old devices ActionBar has introduced in Android 3.0, The ActionBar Sherlock library allow to use the ActionBar on old devices as Android 1.6
  • 35. ActionBar : Home Button The ActionBar shows an icon of your application, this is called the home icon. If you select this icon the onOptionsItemSelected() method will be called with the value android.R.id.home. The recommendation is to return to the main Activity in your program. ActionBar actionbar = getActionBar(); actionbar.setHomeButtonEnabled(true);
  • 37. Workshop: Navigating Up Like home button, ActionBar can use as up navigation or goto parent activity, to enable up button use setDisplayHomeUpEnabled() method. You should include FLAG_ACTIVITY_CLEAR_TOP in the Intent.
  • 39. ActionBar: Action View a custom View can add to ActionBar, use setCustomView method and enable display of custom View via setDisplay methods in ActionBar.DISPLAY_SHOW_CUSTOM flag.
  • 40. Workshop: Action View Create an App with ActionBar, has 2 option menus refresh and setting, after push refresh menu the show the progress bar.
  • 42. ActionBar: Indeterminate progress ActionBar can show progress bar use requestWindowsFeature in request to use interminate progress bar requestWindowFeature(Window. FEATURE_INDETERMINATE_PROGRESS); setProgressBarIndeterminateVisibility(true);
  • 44. ActionBar: Dimming navigation You can also hide the software navigation button in your Android application to have more space available. If the user touches the button of the screen the navigation button are automatically shown again. getWindow(). getDecorView(). setSystemUiVisibility(View. SYSTEM_UI_FLAG_HIDE_NAVIGATION);
  • 46. Notification Android allows to put notification into the titlebar of your application. The user can expand the notification bar and by selecting the notification the user can trigger another activity. Ref: http://developer.android.com/guide/topics/ui/notifiers/notifications.html
  • 47. Notification To create notifications you use the NotificationManager class which can be received from the Context, e.g. an activity or a service, via the getSystemService() method. Notification noti = new Notification.Builder(this) .setContentTitle("Title") .setContentText("Body").build();
  • 48. Notification NotificationManager notificationManager = (NotificationManager) getSystemService (NOTIFICATION_SERVICE); // Hide the notification after its selected noti.flags |= Notification.FLAG_AUTO_CANCEL; notificationManager.notify(0, noti);
  • 49. Workshop: Notification Create App with a single button, after push button the notification will appear in the notification bar and use can cancel notification.
  • 51. End