SlideShare a Scribd company logo
Android Application Development
         User Interface




                                       Ahsanul Karim
                          ahsanul.karim@sentinelbd.com
                               Sentinel Solutions Ltd.
                             http://www.sentinelbd.com
User Interface
Today
The Android Widget Toolbox

1.TextView
2.EditText
3.Spinner
4.Button
5.CheckBox
6.RadioButton
7.DatePicker
8.TimePicker

  We have already used TextView, EditText and Button
User Interface
Android Widget Toolbox
Form Elements Tutorial
This tutorial introduces a variety of widgets that are useful when creating forms,
         1. image buttons,
         2. text fields,
         3. checkboxes,
         4. radio buttons,
         5. Toggle buttons,
         6. Rating bar
User Interface
  Android Widget Toolbox
  Form Elements Tutorial (Contd.)
   1.   Start a new project named HelloFormStuff.
   2.   Create a basic LinearLayout in 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
       Normal   Focused   Pressed             pressed, a short message will be displayed.

 1. Copy the images on the right into the res/drawable/ directory of your project. These will
     be used for the different button states.
 2. 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:




                     Normal             Pressed              After 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.
1. 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).
 1. 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.
  1. 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
User Interface
Android Widget Toolbox
Auto Complete Tutorial
To create a text entry widget that provides auto-complete suggestions, use the
AutoCompleteTextView widget. Suggestions are received from a collection of strings associated
with the widget through an ArrayAdapter
In this tutorial, you will create a AutoCompleteTextView widget that provides suggestions for
a country name.
User Interface
Android Widget Toolbox
Auto Complete Tutorial (Contd.)
1. Start a new project named HelloAutoComplete.
2. Create an XML file named list_item.xml and save it inside the res/layout/ folder.
   Edit the file to look like this:




This file defines a simple TextView that will be used for each item that appears in the list
of suggestions
User Interface
Android Widget Toolbox
Auto Complete Tutorial (Contd.)
3. Open the res/layout/main.xml file and insert the following:




The TextView is a label that introduces the AutoCompleteTextView widget.
User Interface
  Android Widget Toolbox
  Auto Complete Tutorial (Contd.)
   4. Open HelloAutoComplete.java and insert the following code for the onCreate() method:




a. After the content view is set to the main.xml layout, the AutoCompleteTextView widget
is captured from the layout with findViewById(int).

b. A new ArrayAdapter is then initialized to bind the list_item.xml layout to each list item in
the COUNTRIES string array (defined in the next step).

c. Finally, setAdapter() is called to associate the ArrayAdapter with the
AutoCompleteTextView widget so that the string array will populate the list of suggestions.
User Interface
Android Widget Toolbox
Auto Complete Tutorial (Contd.)
5. Inside the HelloAutoComplete class, add the string array:
User Interface
Android Widget Toolbox
Auto Complete Tutorial (Contd.)
6. Run the application
User Interface
Android Widget Toolbox
Auto Complete Tutorial (Contd.)
7. Recommended: This can be done with a <string-array< resource in your
project res/values/strings.xml file. For example:




  8. From source code:

More Related Content

What's hot

Android ui dialog
Android ui dialogAndroid ui dialog
Android ui dialogKrazy Koder
 
Android menus in android-chapter15
Android menus in android-chapter15Android menus in android-chapter15
Android menus in android-chapter15
Dr. Ramkumar Lakshminarayanan
 
Android Architecture.pptx
Android Architecture.pptxAndroid Architecture.pptx
Android Architecture.pptx
priya Nithya
 
Android activities & views
Android activities & viewsAndroid activities & views
Android activities & views
ma-polimi
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
Prawesh Shrestha
 
Android Fragment
Android FragmentAndroid Fragment
Android Fragment
Kan-Han (John) Lu
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android Studio
Suyash Srijan
 
Top 11 Mobile App Development Frameworks
Top 11 Mobile App Development FrameworksTop 11 Mobile App Development Frameworks
Top 11 Mobile App Development Frameworks
Albiorix Technology
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
Aakash Ugale
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorageKrazy Koder
 
Flutter presentation.pptx
Flutter presentation.pptxFlutter presentation.pptx
Flutter presentation.pptx
FalgunSorathiya
 
Android animation
Android animationAndroid animation
Android animationKrazy Koder
 
Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Ahsanul Karim
 
Android app development ppt
Android app development pptAndroid app development ppt
Android app development ppt
saitej15
 
Android service
Android serviceAndroid service
Android service
DENNIS JUNG
 
Android activity lifecycle
Android activity lifecycleAndroid activity lifecycle
Android activity lifecycle
Soham Patel
 
UI controls in Android
UI controls in Android UI controls in Android
UI controls in Android
DivyaKS12
 

What's hot (20)

Android Services
Android ServicesAndroid Services
Android Services
 
AndroidManifest
AndroidManifestAndroidManifest
AndroidManifest
 
Android ui dialog
Android ui dialogAndroid ui dialog
Android ui dialog
 
Android menus in android-chapter15
Android menus in android-chapter15Android menus in android-chapter15
Android menus in android-chapter15
 
Android Architecture.pptx
Android Architecture.pptxAndroid Architecture.pptx
Android Architecture.pptx
 
Android activities & views
Android activities & viewsAndroid activities & views
Android activities & views
 
Introduction to fragments in android
Introduction to fragments in androidIntroduction to fragments in android
Introduction to fragments in android
 
Android Fragment
Android FragmentAndroid Fragment
Android Fragment
 
Introduction to Android and Android Studio
Introduction to Android and Android StudioIntroduction to Android and Android Studio
Introduction to Android and Android Studio
 
Top 11 Mobile App Development Frameworks
Top 11 Mobile App Development FrameworksTop 11 Mobile App Development Frameworks
Top 11 Mobile App Development Frameworks
 
android menus
android menusandroid menus
android menus
 
Data Storage In Android
Data Storage In Android Data Storage In Android
Data Storage In Android
 
Android datastorage
Android datastorageAndroid datastorage
Android datastorage
 
Flutter presentation.pptx
Flutter presentation.pptxFlutter presentation.pptx
Flutter presentation.pptx
 
Android animation
Android animationAndroid animation
Android animation
 
Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)Day: 1 Introduction to Mobile Application Development (in Android)
Day: 1 Introduction to Mobile Application Development (in Android)
 
Android app development ppt
Android app development pptAndroid app development ppt
Android app development ppt
 
Android service
Android serviceAndroid service
Android service
 
Android activity lifecycle
Android activity lifecycleAndroid activity lifecycle
Android activity lifecycle
 
UI controls in Android
UI controls in Android UI controls in Android
UI controls in Android
 

Viewers also liked

GCM for Android
GCM for AndroidGCM for Android
GCM for Android
Ahsanul Karim
 
Action Bar Sherlock tutorial
Action Bar Sherlock tutorialAction Bar Sherlock tutorial
Action Bar Sherlock tutorial
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
 
Training android
Training androidTraining android
Training android
University of Technology
 
Android User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAndroid User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAhsanul Karim
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivityAhsanul Karim
 
Day 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedDay 1 Android: Before Getting Started
Day 1 Android: Before Getting Started
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 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
 
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
Ahsanul Karim
 
Multiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerMultiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerAhsanul 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
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesAhsanul 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
 
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
 
Mcq peresentation
Mcq  peresentationMcq  peresentation
Mcq peresentation
Shah Jalal Hridoy
 

Viewers also liked (18)

GCM for Android
GCM for AndroidGCM for Android
GCM for Android
 
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]
 
Training android
Training androidTraining android
Training android
 
Android User Interface: Basic Form Widgets
Android User Interface: Basic Form WidgetsAndroid User Interface: Basic Form Widgets
Android User Interface: Basic Form Widgets
 
Android MapView and MapActivity
Android MapView and MapActivityAndroid MapView and MapActivity
Android MapView and MapActivity
 
Day 1 Android: Before Getting Started
Day 1 Android: Before Getting StartedDay 1 Android: Before Getting Started
Day 1 Android: Before Getting Started
 
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 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
 
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
 
Multiple Activity and Navigation Primer
Multiple Activity and Navigation PrimerMultiple Activity and Navigation Primer
Multiple Activity and Navigation Primer
 
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
 
Day 3: Getting Active Through Activities
Day 3: Getting Active Through ActivitiesDay 3: Getting Active Through Activities
Day 3: Getting Active Through Activities
 
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)
 
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
 
Client-Server
Client-ServerClient-Server
Client-Server
 
Mcq peresentation
Mcq  peresentationMcq  peresentation
Mcq peresentation
 

Similar to Day 4: Android: UI Widgets

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
 
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
Denis Minja
 
Software engineering modeling lab lectures
Software engineering modeling lab lecturesSoftware engineering modeling lab lectures
Software engineering modeling lab lectures
marwaeng
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
kirupasuchi1996
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
Shrijan Tiwari
 
Keynote + Next Gen UIs.pptx
Keynote + Next Gen UIs.pptxKeynote + Next Gen UIs.pptx
Keynote + Next Gen UIs.pptx
EqraKhattak
 
Intake 38 9
Intake 38 9Intake 38 9
Intake 38 9
Mahmoud Ouf
 
Gui builder
Gui builderGui builder
Gui builderlearnt
 
Intake 37 9
Intake 37 9Intake 37 9
Intake 37 9
Mahmoud Ouf
 
Programming Without Coding Technology (PWCT) - Simple GUI Application
Programming Without Coding Technology (PWCT) - Simple GUI ApplicationProgramming Without Coding Technology (PWCT) - Simple GUI Application
Programming Without Coding Technology (PWCT) - Simple GUI Application
Mahmoud Samir Fayed
 
Create New Android Layout
Create New Android LayoutCreate New Android Layout
Create New Android Layout
Transpose Solutions Inc
 
Programming Without Coding Technology (PWCT) - Tab control
Programming Without Coding Technology (PWCT) - Tab controlProgramming Without Coding Technology (PWCT) - Tab control
Programming Without Coding Technology (PWCT) - Tab control
Mahmoud Samir Fayed
 
Autocad excel vba
Autocad excel vbaAutocad excel vba
Autocad excel vbarjg_vijay
 
Programming Without Coding Technology (PWCT) - Crystal Reports 10
Programming Without Coding Technology (PWCT) - Crystal Reports 10Programming Without Coding Technology (PWCT) - Crystal Reports 10
Programming Without Coding Technology (PWCT) - Crystal Reports 10
Mahmoud Samir Fayed
 
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
Unit IV-Checkboxes    and   Radio Buttons in VB.Net in VB.NET Unit IV-Checkboxes    and   Radio Buttons in VB.Net in VB.NET
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
Ujwala Junghare
 
Programming Without Coding Technology (PWCT) - Functions and Procedures
Programming Without Coding Technology (PWCT) - Functions and ProceduresProgramming Without Coding Technology (PWCT) - Functions and Procedures
Programming Without Coding Technology (PWCT) - Functions and Procedures
Mahmoud Samir Fayed
 
Android session 3
Android session 3Android session 3
Android session 3
Ahesanali Suthar
 

Similar to Day 4: Android: UI Widgets (20)

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
 
4.C#
4.C#4.C#
4.C#
 
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
 
Software engineering modeling lab lectures
Software engineering modeling lab lecturesSoftware engineering modeling lab lectures
Software engineering modeling lab lectures
 
GUI components in Java
GUI components in JavaGUI components in Java
GUI components in Java
 
Introduction to android
Introduction to androidIntroduction to android
Introduction to android
 
Keynote + Next Gen UIs.pptx
Keynote + Next Gen UIs.pptxKeynote + Next Gen UIs.pptx
Keynote + Next Gen UIs.pptx
 
Intake 38 9
Intake 38 9Intake 38 9
Intake 38 9
 
Gui builder
Gui builderGui builder
Gui builder
 
Intake 37 9
Intake 37 9Intake 37 9
Intake 37 9
 
Programming Without Coding Technology (PWCT) - Simple GUI Application
Programming Without Coding Technology (PWCT) - Simple GUI ApplicationProgramming Without Coding Technology (PWCT) - Simple GUI Application
Programming Without Coding Technology (PWCT) - Simple GUI Application
 
Introduction
IntroductionIntroduction
Introduction
 
Create New Android Layout
Create New Android LayoutCreate New Android Layout
Create New Android Layout
 
Programming Without Coding Technology (PWCT) - Tab control
Programming Without Coding Technology (PWCT) - Tab controlProgramming Without Coding Technology (PWCT) - Tab control
Programming Without Coding Technology (PWCT) - Tab control
 
Autocad excel vba
Autocad excel vbaAutocad excel vba
Autocad excel vba
 
Programming Without Coding Technology (PWCT) - Crystal Reports 10
Programming Without Coding Technology (PWCT) - Crystal Reports 10Programming Without Coding Technology (PWCT) - Crystal Reports 10
Programming Without Coding Technology (PWCT) - Crystal Reports 10
 
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
Unit IV-Checkboxes    and   Radio Buttons in VB.Net in VB.NET Unit IV-Checkboxes    and   Radio Buttons in VB.Net in VB.NET
Unit IV-Checkboxes and Radio Buttons in VB.Net in VB.NET
 
UIAutomator
UIAutomatorUIAutomator
UIAutomator
 
Programming Without Coding Technology (PWCT) - Functions and Procedures
Programming Without Coding Technology (PWCT) - Functions and ProceduresProgramming Without Coding Technology (PWCT) - Functions and Procedures
Programming Without Coding Technology (PWCT) - Functions and Procedures
 
Android session 3
Android session 3Android session 3
Android session 3
 

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: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in BackgroundAhsanul 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 API
Ahsanul 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 Component
Ahsanul 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 Study
Ahsanul Karim
 
Sensors in Android (old)
Sensors in Android (old)Sensors in Android (old)
Sensors in Android (old)Ahsanul Karim
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_started
Ahsanul Karim
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3
Ahsanul Karim
 
Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2
Ahsanul Karim
 
Android 1.8 sensor
Android 1.8 sensorAndroid 1.8 sensor
Android 1.8 sensor
Ahsanul Karim
 

More from Ahsanul Karim (17)

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: Working in Background
Day 15: Working in BackgroundDay 15: Working in Background
Day 15: Working in Background
 
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
 
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
 
List Views
List ViewsList Views
List Views
 
Sensors in Android (old)
Sensors in Android (old)Sensors in Android (old)
Sensors in Android (old)
 
Day1 before getting_started
Day1 before getting_startedDay1 before getting_started
Day1 before getting_started
 
Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3Android Workshop: Day 1 Part 3
Android Workshop: Day 1 Part 3
 
Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2Android Workshop Day 1 Part 2
Android Workshop Day 1 Part 2
 
Android 1.8 sensor
Android 1.8 sensorAndroid 1.8 sensor
Android 1.8 sensor
 

Recently uploaded

The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
Laura Byrne
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
RTTS
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Jeffrey Haguewood
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
Safe Software
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
DianaGray10
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
Product School
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Inflectra
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
Cheryl Hung
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
Ralf Eggert
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
CatarinaPereira64715
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
Elena Simperl
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
Fwdays
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
Elena Simperl
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
Thijs Feryn
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
ThousandEyes
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
Frank van Harmelen
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
Product School
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Product School
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
James Anderson
 

Recently uploaded (20)

The Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and SalesThe Art of the Pitch: WordPress Relationships and Sales
The Art of the Pitch: WordPress Relationships and Sales
 
JMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and GrafanaJMeter webinar - integration with InfluxDB and Grafana
JMeter webinar - integration with InfluxDB and Grafana
 
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
Slack (or Teams) Automation for Bonterra Impact Management (fka Social Soluti...
 
Essentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with ParametersEssentials of Automations: Optimizing FME Workflows with Parameters
Essentials of Automations: Optimizing FME Workflows with Parameters
 
UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4UiPath Test Automation using UiPath Test Suite series, part 4
UiPath Test Automation using UiPath Test Suite series, part 4
 
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
AI for Every Business: Unlocking Your Product's Universal Potential by VP of ...
 
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered QualitySoftware Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
Software Delivery At the Speed of AI: Inflectra Invests In AI-Powered Quality
 
Key Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdfKey Trends Shaping the Future of Infrastructure.pdf
Key Trends Shaping the Future of Infrastructure.pdf
 
PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)PHP Frameworks: I want to break free (IPC Berlin 2024)
PHP Frameworks: I want to break free (IPC Berlin 2024)
 
ODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User GroupODC, Data Fabric and Architecture User Group
ODC, Data Fabric and Architecture User Group
 
When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...When stars align: studies in data quality, knowledge graphs, and machine lear...
When stars align: studies in data quality, knowledge graphs, and machine lear...
 
"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi"Impact of front-end architecture on development cost", Viktor Turskyi
"Impact of front-end architecture on development cost", Viktor Turskyi
 
FIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdfFIDO Alliance Osaka Seminar: Overview.pdf
FIDO Alliance Osaka Seminar: Overview.pdf
 
Knowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and backKnowledge engineering: from people to machines and back
Knowledge engineering: from people to machines and back
 
Accelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish CachingAccelerate your Kubernetes clusters with Varnish Caching
Accelerate your Kubernetes clusters with Varnish Caching
 
Assuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyesAssuring Contact Center Experiences for Your Customers With ThousandEyes
Assuring Contact Center Experiences for Your Customers With ThousandEyes
 
Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*Neuro-symbolic is not enough, we need neuro-*semantic*
Neuro-symbolic is not enough, we need neuro-*semantic*
 
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
De-mystifying Zero to One: Design Informed Techniques for Greenfield Innovati...
 
Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...Designing Great Products: The Power of Design and Leadership by Chief Designe...
Designing Great Products: The Power of Design and Leadership by Chief Designe...
 
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
GDG Cloud Southlake #33: Boule & Rebala: Effective AppSec in SDLC using Deplo...
 

Day 4: Android: UI Widgets

  • 1. Android Application Development User Interface Ahsanul Karim ahsanul.karim@sentinelbd.com Sentinel Solutions Ltd. http://www.sentinelbd.com
  • 2. User Interface Today The Android Widget Toolbox 1.TextView 2.EditText 3.Spinner 4.Button 5.CheckBox 6.RadioButton 7.DatePicker 8.TimePicker We have already used TextView, EditText and Button
  • 3. User Interface Android Widget Toolbox Form Elements Tutorial This tutorial introduces a variety of widgets that are useful when creating forms, 1. image buttons, 2. text fields, 3. checkboxes, 4. radio buttons, 5. Toggle buttons, 6. Rating bar
  • 4. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.) 1. Start a new project named HelloFormStuff. 2. Create a basic LinearLayout in res/layout/main.xml 3. onCreate()
  • 5. 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 Normal Focused Pressed pressed, a short message will be displayed. 1. Copy the images on the right into the res/drawable/ directory of your project. These will be used for the different button states. 2. 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.
  • 6. 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
  • 7. 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: Normal Pressed After Pressed
  • 8. 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.
  • 9. 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:
  • 10. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Edit Text
  • 11. 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):
  • 12. 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:
  • 13. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Check Box
  • 14. 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. 1. 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
  • 15. 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:
  • 16. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Radio Button
  • 17. 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). 1. Open the res/layout/main.xml file and add the ToggleButton element (inside the LinearLayout):
  • 18. 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.
  • 19. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Toggle Button
  • 20. 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. 1. 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:
  • 21. User Interface Android Widget Toolbox Form Elements Tutorial (Contd.)- Rating Bar
  • 22. User Interface Android Widget Toolbox Auto Complete Tutorial To create a text entry widget that provides auto-complete suggestions, use the AutoCompleteTextView widget. Suggestions are received from a collection of strings associated with the widget through an ArrayAdapter In this tutorial, you will create a AutoCompleteTextView widget that provides suggestions for a country name.
  • 23. User Interface Android Widget Toolbox Auto Complete Tutorial (Contd.) 1. Start a new project named HelloAutoComplete. 2. Create an XML file named list_item.xml and save it inside the res/layout/ folder. Edit the file to look like this: This file defines a simple TextView that will be used for each item that appears in the list of suggestions
  • 24. User Interface Android Widget Toolbox Auto Complete Tutorial (Contd.) 3. Open the res/layout/main.xml file and insert the following: The TextView is a label that introduces the AutoCompleteTextView widget.
  • 25. User Interface Android Widget Toolbox Auto Complete Tutorial (Contd.) 4. Open HelloAutoComplete.java and insert the following code for the onCreate() method: a. After the content view is set to the main.xml layout, the AutoCompleteTextView widget is captured from the layout with findViewById(int). b. A new ArrayAdapter is then initialized to bind the list_item.xml layout to each list item in the COUNTRIES string array (defined in the next step). c. Finally, setAdapter() is called to associate the ArrayAdapter with the AutoCompleteTextView widget so that the string array will populate the list of suggestions.
  • 26. User Interface Android Widget Toolbox Auto Complete Tutorial (Contd.) 5. Inside the HelloAutoComplete class, add the string array:
  • 27. User Interface Android Widget Toolbox Auto Complete Tutorial (Contd.) 6. Run the application
  • 28. User Interface Android Widget Toolbox Auto Complete Tutorial (Contd.) 7. Recommended: This can be done with a <string-array< resource in your project res/values/strings.xml file. For example: 8. From source code: