SlideShare a Scribd company logo
1 of 44
Android Application Development User Interface Ahsanul Karim ahsanul.karim@sentinelbd.com Sentinel Solutions Ltd. http://www.sentinelbd.com
User Interface Android User Interface: Day 7 The Android Widget Toolbox TextView EditText Spinner Button CheckBox RadioButton DatePicker TimePicker Layouts FrameLayout LinearLayout RelativeLayout TableLayout AbsoluteLayout GridLayout Tab Layout We have already used TextView, EditText and Button
User Interface Today The Android Widget Toolbox TextView EditText Spinner Button CheckBox RadioButton DatePicker TimePicker We have already used TextView, EditText and Button
User Interface Android Widget Toolbox Date Picker Tutorial To provide a widget for selecting a date, use the DatePicker widget, which allows the user to  select the month, day, and year, in a familiar interface. We’ll create a DatePickerDialog, which presents the date picker in a floating dialog box at the press of a button.  When the date is set by the user, a TextView will update with the new  ate.
User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) Start a new project named HelloDatePicker. Open the res/layout/main.xml file and insert the following: This creates a basic LinearLayout with a TextView that will display the date and a Button that  will open the DatePickerDialog.
User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 3. Open HelloDatePicker.java  4. add the following members to the class
User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 5. Now we add following code in onCreate() method to capture View elements and add  listener to the Button. 6. Now we show the dialog in button action
User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) First, the content is set to the main.xml layout.  Then the TextView and Button elements are captured from the layout with  findViewById(int).  A new View.OnClickListeneris created for the Button, so that when it is clicked,  it will call  showDialog(int), passing the unique integer ID for the date picker  dialog.  Using showDialog(int) allows the Activity to manage the life-cycle of the dialog  	and will call the onCreateDialog(int) callback method to request the Dialog that        should be displayed.
User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 5. Now we need to add a DataSetListener which will invoke when user selects a date
User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 6. Now we see
User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 6. Now we add this method to show the date in display TextView
User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 7. We set the selected date in DatePicker and get it from callback
User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 8. We add the following code to initiate with current date
User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 2. onCreate
User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 3. callback method for creating dialog 4. Initialize a new  DatePickerDialog.OnDateSetListener for when the user has set the date  (by clicking the "Set" button)
User Interface Android Widget Toolbox Date Picker Tutorial (Cont.)
User Interface Android Widget Toolbox Time Picker Tutorial To provide a widget for selecting a date, use the TimePicker widget, which allows the user to  select the hour and minute in a familiar interface. We’ll create a TimePickerDialog, which presents the date picker in a floating dialog box at the press of a button.  When the time is set by the user, a TextView will update with the new  time. Do it yourself
User Interface Android Widget Toolbox Time Picker Tutorial (Contd.) Hints:
User Interface Android Widget Toolbox Spinner Tutorial Spinner is a widget similar to a drop-down list for selecting items. In this tutorial, you'll create a simple spinner widget that displays a list of planets.  When one is selected, a toast message will display the selected item.
User Interface Android Widget Toolbox Spinner Tutorial (Contd.) Start a new project named HelloSpinner Open the res/layout/main.xml file and insert the following: Notice that the TextView's android:text attribute and the Spinner's android:prompt attribute  both reference the same string resource. This text behaves as a title for the widget. When  applied to the Spinner, the title text will appear in the selection dialog that appears upon  selecting the widget.
User Interface Android Widget Toolbox Spinner Tutorial (Contd.) 3. Create a strings.xml file in res/values/ and edit the file to look like this:  The <string> element defines the title string referenced by the TextView and Spinner in  the layout above. The <string-array element defines the list of strings that will be displayed  as the list in the Spinner widget.
User Interface Android Widget Toolbox Spinner Tutorial (Contd.) 4. Now open the HelloSpinner.java file and insert the following code for the onCreate()  method: After the main.xml layout is set as the content view, the Spinner widget is captured from  the layout with findViewById(int). The createFromResource() method then creates a new ArrayAdapter, which binds each item  in the string array to the initial appearance for the Spinner TheR.array.planets_array ID references the string-array defined above and the  android.R.layout.simple_spinner_item ID references a layout for the standard spinner  appearance, defined by the platform.
User Interface Android Widget Toolbox Spinner Tutorial (Contd.) 5. Now create a nested class that implements AdapterView.OnItemSelectedListener.  This will provide a callback method that will notify your application when an item has  been selected from the Spinner. Here's what this class should look like This will work both for array from resources or static String array The AdapterView.OnItemSelectedListener requires the onItemSelected() and  onNothingSelected() callback methods.
User Interface Android Widget Toolbox Spinner Tutorial (Contd.) 6. Now the MyOnItemSelectedListener needs to be applied to the Spinner.  Go back to the onCreate() method and add the following line to the end:
User Interface Android Widget Toolbox Spinner Tutorial (Contd.) Run the application
User Interface Android Widget Toolbox Form Elements Tutorial This tutorial introduces a variety of widgets that are useful when creating forms,  image buttons,  text fields,  checkboxes,  radio buttons, Toggle buttons, Rating bar
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.) Start a new project named HelloFormStuff. Create a basic LinearLayoutin res/layout/main.xml  3. onCreate() 
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Custom Button We’ll create an image button with 3 states Using the Button widget and an XML file that defines three different images to use for the  different button states. When the button is pressed, a short message will be displayed. Normal Focused Pressed Copy the images on the right into the res/drawable/ directory of your project. These will  be used for the different button states. Create a new file in the res/drawable/ directory named android_button.xml.  Insert the following XML: This defines a single drawable resource, which will change its image based on the current state  of the button.
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Custom Button 3. Open the res/layout/main.xml file and add the Button element: The android:background attribute specifies the drawable resource to use for the button background (which, when saved at res/drawable/android.xml,  is referenced as @drawable/android). This replaces the normal background image used for  buttons throughout the system. In order for the drawable to change its image based on the  button state, the image must be applied to the background
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Custom Button 4. o make the button do something when pressed, add the following code at the end of the  onCreate() method: After Pressed Normal Pressed
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Edit Text In this section, you will create a text field for user input, using the EditText widget. Once text  has been entered into the field, the "Enter" key will display the text in a toast message. 1. Open the res/layout/main.xml file and add the EditText element (inside the LinearLayout): 2.
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Edit Text 2. To do something with the text that the user types, add the following code to the end of the  onCreate() method:
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Edit Text
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Check Box In this section, you will create a checkbox for selecting items, using the CheckBox widget.  When the checkbox is pressed, a toast message will indicate the current state of the checkbox. 1. Open the res/layout/main.xml file and add the CheckBox element (inside the LinearLayout):
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Check Box 2. To do something when the state is changed, add the following code to the end of the  onCreate() method:
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Check Box
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Radio Button In this section, you will create two mutually-exclusive radio buttons (enabling one disables the  other), using the RadioGroup and RadioButton widgets.  When either radio button is pressed, a toast message will be displayed. Open the res/layout/main.xml file and add two RadioButtons, nested in a RadioGroup  (inside the LinearLayout): It's important that the RadioButtons are grouped together by the RadioGroup element so that  no more than one can be selected at a time. This logic is automatically handled by the Android  system. When one RadioButton within a group is selected, all others are automatically deselected
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Radio Button 2. To do something when each RadioButton is selected, you need an View.OnClickListener.  In this case, you want the listener to be re-usable, so add the following code to create a new  member in the HelloFormStuff Activity 3. Now, at the bottom of the onCreate() method, add the following:
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Radio Button
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Toggle Button In this section, you'll create a button used specifically for toggling between two states, using  the ToggleButton widget. This widget is an excellent alternative to radio buttons if you have  two simple states that are mutually exclusive ("on" and "off", for example). Open the res/layout/main.xml file and add the ToggleButton element (inside the  LinearLayout):
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Toggle Button 2. To do something when the state is changed, add the following code to the end of the  onCreate() method: This captures the ToggleButton element from the layout, then adds an View.OnClickListener.  The View.OnClickListener must implement the onClick(View) callback method, which defines  the action to perform when the button is clicked. In this example, the callback method checks  the new state of the button, then shows a Toast message that indicates the current state.
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Toggle Button
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Rating Bar In this section, you'll create a widget that allows the user to provide a rating, with the  RatingBar widget. Open the res/layout/main.xml file and add the RatingBar element (inside the  LinearLayout): 2. To do something when a new rating has been set, add the following code to the end of  the onCreate() method:
User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Rating Bar

More Related Content

What's hot

android layouts
android layoutsandroid layouts
android layoutsDeepa Rani
 
Asp.Net Core MVC with Entity Framework
Asp.Net Core MVC with Entity FrameworkAsp.Net Core MVC with Entity Framework
Asp.Net Core MVC with Entity FrameworkShravan A
 
Android User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAndroid User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAhsanul Karim
 
The Full Stack Web Development
The Full Stack Web DevelopmentThe Full Stack Web Development
The Full Stack Web DevelopmentSam Dias
 
Android activity lifecycle
Android activity lifecycleAndroid activity lifecycle
Android activity lifecycleSoham Patel
 
Lecture 1 introduction to vb.net
Lecture 1   introduction to vb.netLecture 1   introduction to vb.net
Lecture 1 introduction to vb.netMUKALU STEVEN
 
Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net frameworkArun Prasad
 
Android SDK Tutorial | Edureka
Android SDK Tutorial | EdurekaAndroid SDK Tutorial | Edureka
Android SDK Tutorial | EdurekaEdureka!
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android DevelopmentAly Abdelkareem
 
Android activity
Android activityAndroid activity
Android activityKrazy Koder
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studioParinita03
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application FrameworkYong Heui Cho
 
Asp.net Lab manual
Asp.net Lab manualAsp.net Lab manual
Asp.net Lab manualTamil Dhasan
 

What's hot (20)

android layouts
android layoutsandroid layouts
android layouts
 
Asp.Net Core MVC with Entity Framework
Asp.Net Core MVC with Entity FrameworkAsp.Net Core MVC with Entity Framework
Asp.Net Core MVC with Entity Framework
 
Android User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAndroid User Interface: Basic Form Widgets
Android User Interface: Basic Form Widgets
 
The Full Stack Web Development
The Full Stack Web DevelopmentThe Full Stack Web Development
The Full Stack Web Development
 
Android activity lifecycle
Android activity lifecycleAndroid activity lifecycle
Android activity lifecycle
 
Lecture 1 introduction to vb.net
Lecture 1   introduction to vb.netLecture 1   introduction to vb.net
Lecture 1 introduction to vb.net
 
Introduction to .net framework
Introduction to .net frameworkIntroduction to .net framework
Introduction to .net framework
 
Android SDK Tutorial | Edureka
Android SDK Tutorial | EdurekaAndroid SDK Tutorial | Edureka
Android SDK Tutorial | Edureka
 
SQLITE Android
SQLITE AndroidSQLITE Android
SQLITE Android
 
Introduction to Android Development
Introduction to Android DevelopmentIntroduction to Android Development
Introduction to Android Development
 
Android activity
Android activityAndroid activity
Android activity
 
Ado.Net Tutorial
Ado.Net TutorialAdo.Net Tutorial
Ado.Net Tutorial
 
AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
 
Creating the first app with android studio
Creating the first app with android studioCreating the first app with android studio
Creating the first app with android studio
 
Android - Application Framework
Android - Application FrameworkAndroid - Application Framework
Android - Application Framework
 
ADO.NET
ADO.NETADO.NET
ADO.NET
 
Php mysql ppt
Php mysql pptPhp mysql ppt
Php mysql ppt
 
Introduction to Visual Studio.NET
Introduction to Visual Studio.NETIntroduction to Visual Studio.NET
Introduction to Visual Studio.NET
 
Asp.net Lab manual
Asp.net Lab manualAsp.net Lab manual
Asp.net Lab manual
 
GRID VIEW PPT
GRID VIEW PPTGRID VIEW PPT
GRID VIEW PPT
 

Viewers also liked

Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2Ahsanul Karim
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI WidgetsAhsanul Karim
 
Day 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location APIDay 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location APIAhsanul Karim
 
Action Bar Sherlock tutorial
Action Bar Sherlock tutorialAction Bar Sherlock tutorial
Action Bar Sherlock tutorialAhsanul 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
 
Day 15: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in BackgroundAhsanul 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 & PreferencesAhsanul Karim
 
Day 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedDay 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedAhsanul Karim
 
Lecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick OverviewLecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick OverviewAhsanul Karim
 
Multiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerMultiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerAhsanul Karim
 
Introduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedIntroduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedAhsanul Karim
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesAhsanul Karim
 
Lecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedLecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedAhsanul Karim
 
Android before getting started
Android before getting startedAndroid before getting started
Android before getting startedAhsanul Karim
 
Ui layout (incomplete)
Ui layout (incomplete)Ui layout (incomplete)
Ui layout (incomplete)Ahsanul Karim
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_startedAhsanul Karim
 

Viewers also liked (17)

Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2
 
Day 4: Android: UI Widgets
Day 4: Android: UI WidgetsDay 4: Android: UI Widgets
Day 4: Android: UI Widgets
 
Day 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location APIDay 9: Make Your App Location Aware using Location API
Day 9: Make Your App Location Aware using Location API
 
Action Bar Sherlock tutorial
Action Bar Sherlock tutorialAction Bar Sherlock tutorial
Action Bar Sherlock tutorial
 
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]
 
Day 15: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in Background
 
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
 
Day 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedDay 1 Android: Before Getting Started
Day 1 Android: Before Getting Started
 
Lecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick OverviewLecture 2(b) Android Internals A Quick Overview
Lecture 2(b) Android Internals A Quick Overview
 
Multiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerMultiple Activity and Navigation Primer
Multiple Activity and Navigation Primer
 
Introduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting StartedIntroduction to Android Development: Before Getting Started
Introduction to Android Development: Before Getting Started
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
 
Client-Server
Client-ServerClient-Server
Client-Server
 
Lecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting StartedLecture 1 Session 1 Before Getting Started
Lecture 1 Session 1 Before Getting Started
 
Android before getting started
Android before getting startedAndroid before getting started
Android before getting started
 
Ui layout (incomplete)
Ui layout (incomplete)Ui layout (incomplete)
Ui layout (incomplete)
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_started
 

Similar to Android User Interface Tutorial: DatePicker, TimePicker & Spinner

Android Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidAndroid Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidDenis Minja
 
Android App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UIAndroid App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UIAnuchit Chalothorn
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to androidShrijan Tiwari
 
Create yourfirstandroidapppdf
Create yourfirstandroidapppdfCreate yourfirstandroidapppdf
Create yourfirstandroidapppdfmurad3003
 
CS6611 Mobile Application Development Lab Manual-2018-19
CS6611 Mobile Application Development Lab Manual-2018-19CS6611 Mobile Application Development Lab Manual-2018-19
CS6611 Mobile Application Development Lab Manual-2018-19Gobinath Subramaniam
 
What is Android?
What is Android?What is Android?
What is Android?ndalban
 
Android Tutorials : Basic widgets
Android Tutorials : Basic widgetsAndroid Tutorials : Basic widgets
Android Tutorials : Basic widgetsPrajyot Mainkar
 
AndroidLab_IT.pptx
AndroidLab_IT.pptxAndroidLab_IT.pptx
AndroidLab_IT.pptxAhmedKedir9
 
ANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.docANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.docPalakjaiswal43
 
Android Application Development - Level 1
Android Application Development - Level 1Android Application Development - Level 1
Android Application Development - Level 1Isham Rashik
 

Similar to Android User Interface Tutorial: DatePicker, TimePicker & Spinner (20)

Android Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_androidAndroid Bootcamp Tanzania:understanding ui in_android
Android Bootcamp Tanzania:understanding ui in_android
 
Notes Unit4.pptx
Notes Unit4.pptxNotes Unit4.pptx
Notes Unit4.pptx
 
Android App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UIAndroid App Development 03 : Widget &amp; UI
Android App Development 03 : Widget &amp; UI
 
Ap quiz app
Ap quiz appAp quiz app
Ap quiz app
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Android
AndroidAndroid
Android
 
Create New Android Layout
Create New Android LayoutCreate New Android Layout
Create New Android Layout
 
4.C#
4.C#4.C#
4.C#
 
unit 4.docx
unit 4.docxunit 4.docx
unit 4.docx
 
Create yourfirstandroidapppdf
Create yourfirstandroidapppdfCreate yourfirstandroidapppdf
Create yourfirstandroidapppdf
 
UIAutomator
UIAutomatorUIAutomator
UIAutomator
 
CS6611 Mobile Application Development Lab Manual-2018-19
CS6611 Mobile Application Development Lab Manual-2018-19CS6611 Mobile Application Development Lab Manual-2018-19
CS6611 Mobile Application Development Lab Manual-2018-19
 
Intake 37 9
Intake 37 9Intake 37 9
Intake 37 9
 
What is Android?
What is Android?What is Android?
What is Android?
 
Intake 38 9
Intake 38 9Intake 38 9
Intake 38 9
 
Android Tutorials : Basic widgets
Android Tutorials : Basic widgetsAndroid Tutorials : Basic widgets
Android Tutorials : Basic widgets
 
AndroidLab_IT.pptx
AndroidLab_IT.pptxAndroidLab_IT.pptx
AndroidLab_IT.pptx
 
ANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.docANDROID LAB MANUAL.doc
ANDROID LAB MANUAL.doc
 
Hats tutorial custom widget
Hats tutorial   custom widgetHats tutorial   custom widget
Hats tutorial custom widget
 
Android Application Development - Level 1
Android Application Development - Level 1Android Application Development - Level 1
Android Application Development - Level 1
 

More from Ahsanul Karim

Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities Ahsanul Karim
 
লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে: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 APIAhsanul Karim
 
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 ListViewsAhsanul Karim
 
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 ListViewsAhsanul Karim
 
Day 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentDay 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentAhsanul Karim
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycleAhsanul Karim
 
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 ActivitiesAhsanul Karim
 
Day 2 android internals a quick overview
Day 2 android internals a quick overviewDay 2 android internals a quick overview
Day 2 android internals a quick overviewAhsanul Karim
 
Mobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete StudyMobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete StudyAhsanul Karim
 
Sensors in Android (old)
Sensors in Android (old)Sensors in Android (old)
Sensors in Android (old)Ahsanul Karim
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Ahsanul Karim
 

More from Ahsanul Karim (15)

Lecture 3 getting active through activities
Lecture 3 getting active through activities Lecture 3 getting active through activities
Lecture 3 getting active through activities
 
লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:লেকচার ১ (ক)- শুরুর আগে:
লেকচার ১ (ক)- শুরুর আগে:
 
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
 
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
 
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
 
Day 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver ComponentDay 6: Android BroadcastReceiver Component
Day 6: Android BroadcastReceiver Component
 
Day 4: Activity lifecycle
Day 4: Activity lifecycleDay 4: Activity lifecycle
Day 4: Activity lifecycle
 
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
 
Day 2 android internals a quick overview
Day 2 android internals a quick overviewDay 2 android internals a quick overview
Day 2 android internals a quick overview
 
Mobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete StudyMobile Banking in Bangladesh: An Incomplete Study
Mobile Banking in Bangladesh: An Incomplete Study
 
GCM for Android
GCM for AndroidGCM for Android
GCM for Android
 
List Views
List ViewsList Views
List Views
 
Sensors in Android (old)
Sensors in Android (old)Sensors in Android (old)
Sensors in Android (old)
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3
 
Android 1.8 sensor
Android 1.8 sensorAndroid 1.8 sensor
Android 1.8 sensor
 

Recently uploaded

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxGaneshChakor2
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupJonathanParaisoCruz
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationnomboosow
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxAvyJaneVismanos
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsanshu789521
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfUjwalaBharambe
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxNirmalaLoungPoorunde1
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxJiesonDelaCerna
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Educationpboyjonauth
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)eniolaolutunde
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17Celine George
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTiammrhaywood
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...jaredbarbolino94
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdfssuser54595a
 

Recently uploaded (20)

CARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptxCARE OF CHILD IN INCUBATOR..........pptx
CARE OF CHILD IN INCUBATOR..........pptx
 
ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)ESSENTIAL of (CS/IT/IS) class 06 (database)
ESSENTIAL of (CS/IT/IS) class 06 (database)
 
MARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized GroupMARGINALIZATION (Different learners in Marginalized Group
MARGINALIZATION (Different learners in Marginalized Group
 
Interactive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communicationInteractive Powerpoint_How to Master effective communication
Interactive Powerpoint_How to Master effective communication
 
Final demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptxFinal demo Grade 9 for demo Plan dessert.pptx
Final demo Grade 9 for demo Plan dessert.pptx
 
Presiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha electionsPresiding Officer Training module 2024 lok sabha elections
Presiding Officer Training module 2024 lok sabha elections
 
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdfFraming an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
Framing an Appropriate Research Question 6b9b26d93da94caf993c038d9efcdedb.pdf
 
Employee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptxEmployee wellbeing at the workplace.pptx
Employee wellbeing at the workplace.pptx
 
CELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptxCELL CYCLE Division Science 8 quarter IV.pptx
CELL CYCLE Division Science 8 quarter IV.pptx
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Introduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher EducationIntroduction to ArtificiaI Intelligence in Higher Education
Introduction to ArtificiaI Intelligence in Higher Education
 
Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)Software Engineering Methodologies (overview)
Software Engineering Methodologies (overview)
 
How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17How to Configure Email Server in Odoo 17
How to Configure Email Server in Odoo 17
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPTECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
ECONOMIC CONTEXT - LONG FORM TV DRAMA - PPT
 
Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...Historical philosophical, theoretical, and legal foundations of special and i...
Historical philosophical, theoretical, and legal foundations of special and i...
 
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝Model Call Girl in Bikash Puri  Delhi reach out to us at 🔝9953056974🔝
Model Call Girl in Bikash Puri Delhi reach out to us at 🔝9953056974🔝
 
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdfTataKelola dan KamSiber Kecerdasan Buatan v022.pdf
TataKelola dan KamSiber Kecerdasan Buatan v022.pdf
 
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
18-04-UA_REPORT_MEDIALITERAСY_INDEX-DM_23-1-final-eng.pdf
 

Android User Interface Tutorial: DatePicker, TimePicker & Spinner

  • 1. Android Application Development User Interface Ahsanul Karim ahsanul.karim@sentinelbd.com Sentinel Solutions Ltd. http://www.sentinelbd.com
  • 2. User Interface Android User Interface: Day 7 The Android Widget Toolbox TextView EditText Spinner Button CheckBox RadioButton DatePicker TimePicker Layouts FrameLayout LinearLayout RelativeLayout TableLayout AbsoluteLayout GridLayout Tab Layout We have already used TextView, EditText and Button
  • 3. User Interface Today The Android Widget Toolbox TextView EditText Spinner Button CheckBox RadioButton DatePicker TimePicker We have already used TextView, EditText and Button
  • 4. User Interface Android Widget Toolbox Date Picker Tutorial To provide a widget for selecting a date, use the DatePicker widget, which allows the user to select the month, day, and year, in a familiar interface. We’ll create a DatePickerDialog, which presents the date picker in a floating dialog box at the press of a button. When the date is set by the user, a TextView will update with the new ate.
  • 5. User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) Start a new project named HelloDatePicker. Open the res/layout/main.xml file and insert the following: This creates a basic LinearLayout with a TextView that will display the date and a Button that will open the DatePickerDialog.
  • 6. User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 3. Open HelloDatePicker.java  4. add the following members to the class
  • 7. User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 5. Now we add following code in onCreate() method to capture View elements and add listener to the Button. 6. Now we show the dialog in button action
  • 8. User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) First, the content is set to the main.xml layout. Then the TextView and Button elements are captured from the layout with  findViewById(int). A new View.OnClickListeneris created for the Button, so that when it is clicked, it will call  showDialog(int), passing the unique integer ID for the date picker dialog. Using showDialog(int) allows the Activity to manage the life-cycle of the dialog and will call the onCreateDialog(int) callback method to request the Dialog that should be displayed.
  • 9. User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 5. Now we need to add a DataSetListener which will invoke when user selects a date
  • 10. User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 6. Now we see
  • 11. User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 6. Now we add this method to show the date in display TextView
  • 12. User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 7. We set the selected date in DatePicker and get it from callback
  • 13. User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 8. We add the following code to initiate with current date
  • 14. User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 2. onCreate
  • 15. User Interface Android Widget Toolbox Date Picker Tutorial (Cont.) 3. callback method for creating dialog 4. Initialize a new  DatePickerDialog.OnDateSetListener for when the user has set the date (by clicking the "Set" button)
  • 16. User Interface Android Widget Toolbox Date Picker Tutorial (Cont.)
  • 17. User Interface Android Widget Toolbox Time Picker Tutorial To provide a widget for selecting a date, use the TimePicker widget, which allows the user to select the hour and minute in a familiar interface. We’ll create a TimePickerDialog, which presents the date picker in a floating dialog box at the press of a button. When the time is set by the user, a TextView will update with the new time. Do it yourself
  • 18. User Interface Android Widget Toolbox Time Picker Tutorial (Contd.) Hints:
  • 19. User Interface Android Widget Toolbox Spinner Tutorial Spinner is a widget similar to a drop-down list for selecting items. In this tutorial, you'll create a simple spinner widget that displays a list of planets. When one is selected, a toast message will display the selected item.
  • 20. User Interface Android Widget Toolbox Spinner Tutorial (Contd.) Start a new project named HelloSpinner Open the res/layout/main.xml file and insert the following: Notice that the TextView's android:text attribute and the Spinner's android:prompt attribute both reference the same string resource. This text behaves as a title for the widget. When applied to the Spinner, the title text will appear in the selection dialog that appears upon selecting the widget.
  • 21. User Interface Android Widget Toolbox Spinner Tutorial (Contd.) 3. Create a strings.xml file in res/values/ and edit the file to look like this: The <string> element defines the title string referenced by the TextView and Spinner in the layout above. The <string-array element defines the list of strings that will be displayed as the list in the Spinner widget.
  • 22. User Interface Android Widget Toolbox Spinner Tutorial (Contd.) 4. Now open the HelloSpinner.java file and insert the following code for the onCreate()  method: After the main.xml layout is set as the content view, the Spinner widget is captured from the layout with findViewById(int). The createFromResource() method then creates a new ArrayAdapter, which binds each item in the string array to the initial appearance for the Spinner TheR.array.planets_array ID references the string-array defined above and the  android.R.layout.simple_spinner_item ID references a layout for the standard spinner appearance, defined by the platform.
  • 23. User Interface Android Widget Toolbox Spinner Tutorial (Contd.) 5. Now create a nested class that implements AdapterView.OnItemSelectedListener. This will provide a callback method that will notify your application when an item has been selected from the Spinner. Here's what this class should look like This will work both for array from resources or static String array The AdapterView.OnItemSelectedListener requires the onItemSelected() and  onNothingSelected() callback methods.
  • 24. User Interface Android Widget Toolbox Spinner Tutorial (Contd.) 6. Now the MyOnItemSelectedListener needs to be applied to the Spinner. Go back to the onCreate() method and add the following line to the end:
  • 25. User Interface Android Widget Toolbox Spinner Tutorial (Contd.) Run the application
  • 26. User Interface Android Widget Toolbox Form Elements Tutorial This tutorial introduces a variety of widgets that are useful when creating forms, image buttons, text fields, checkboxes, radio buttons, Toggle buttons, Rating bar
  • 27. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.) Start a new project named HelloFormStuff. Create a basic LinearLayoutin res/layout/main.xml  3. onCreate() 
  • 28. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Custom Button We’ll create an image button with 3 states Using the Button widget and an XML file that defines three different images to use for the different button states. When the button is pressed, a short message will be displayed. Normal Focused Pressed Copy the images on the right into the res/drawable/ directory of your project. These will be used for the different button states. Create a new file in the res/drawable/ directory named android_button.xml. Insert the following XML: This defines a single drawable resource, which will change its image based on the current state of the button.
  • 29. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Custom Button 3. Open the res/layout/main.xml file and add the Button element: The android:background attribute specifies the drawable resource to use for the button background (which, when saved at res/drawable/android.xml, is referenced as @drawable/android). This replaces the normal background image used for buttons throughout the system. In order for the drawable to change its image based on the button state, the image must be applied to the background
  • 30. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Custom Button 4. o make the button do something when pressed, add the following code at the end of the  onCreate() method: After Pressed Normal Pressed
  • 31. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Edit Text In this section, you will create a text field for user input, using the EditText widget. Once text has been entered into the field, the "Enter" key will display the text in a toast message. 1. Open the res/layout/main.xml file and add the EditText element (inside the LinearLayout): 2.
  • 32. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Edit Text 2. To do something with the text that the user types, add the following code to the end of the  onCreate() method:
  • 33. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Edit Text
  • 34. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Check Box In this section, you will create a checkbox for selecting items, using the CheckBox widget. When the checkbox is pressed, a toast message will indicate the current state of the checkbox. 1. Open the res/layout/main.xml file and add the CheckBox element (inside the LinearLayout):
  • 35. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Check Box 2. To do something when the state is changed, add the following code to the end of the  onCreate() method:
  • 36. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Check Box
  • 37. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Radio Button In this section, you will create two mutually-exclusive radio buttons (enabling one disables the other), using the RadioGroup and RadioButton widgets. When either radio button is pressed, a toast message will be displayed. Open the res/layout/main.xml file and add two RadioButtons, nested in a RadioGroup  (inside the LinearLayout): It's important that the RadioButtons are grouped together by the RadioGroup element so that no more than one can be selected at a time. This logic is automatically handled by the Android system. When one RadioButton within a group is selected, all others are automatically deselected
  • 38. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Radio Button 2. To do something when each RadioButton is selected, you need an View.OnClickListener. In this case, you want the listener to be re-usable, so add the following code to create a new member in the HelloFormStuff Activity 3. Now, at the bottom of the onCreate() method, add the following:
  • 39. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Radio Button
  • 40. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Toggle Button In this section, you'll create a button used specifically for toggling between two states, using the ToggleButton widget. This widget is an excellent alternative to radio buttons if you have two simple states that are mutually exclusive ("on" and "off", for example). Open the res/layout/main.xml file and add the ToggleButton element (inside the  LinearLayout):
  • 41. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Toggle Button 2. To do something when the state is changed, add the following code to the end of the  onCreate() method: This captures the ToggleButton element from the layout, then adds an View.OnClickListener. The View.OnClickListener must implement the onClick(View) callback method, which defines the action to perform when the button is clicked. In this example, the callback method checks the new state of the button, then shows a Toast message that indicates the current state.
  • 42. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Toggle Button
  • 43. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Rating Bar In this section, you'll create a widget that allows the user to provide a rating, with the  RatingBar widget. Open the res/layout/main.xml file and add the RatingBar element (inside the  LinearLayout): 2. To do something when a new rating has been set, add the following code to the end of the onCreate() method:
  • 44. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Rating Bar