SlideShare a Scribd company logo
1 of 22
Download to read offline
Android Programming




         Lesson 3
Using Selection Widgets

       NGUYEN The Linh
Android Programming


Contents

     1     Introducing Adapters

     2     Using Selection Widgets


     3     Exercise 3




                          2
Android Programming


Using Selection Widgets




         Introducing Adapters




                  3
Android Programming


Introducing Adapters

 Adapters are bridging classes that bind data to user-
  interface Views.
 Using ArrayAdapter
    The ArrayAdapter is a generic class that binds AdapterViews to an array of
     objects.

    By default, the ArrayAdapter binds the toString() value of each object to a
     TextView control defined within a layout.

    To apply an Adapter to an AdapterView-derived class, you call the View’s
     setAdapter() method, passing in an Adapter instance, as shown in the snippet
     below:

                                         4
Android Programming


Introducing Adapters

 Using ArrayAdapter (cont.)




                         5
Android Programming


Introducing Adapters

 Example 3.1
    Using Basic ArrayAdapter
    Example 3.1 project
       • MainActivity.java
       • activity_main.xml




                                6
Android Programming


Introducing Adapters

 Custom ArrayAdapter
    You can subclass ArrayAdapter and override getView() to “roll
     your own” views:




                                7
Android Programming


Using Selection Widgets




        Using Selection Widgets




                  8
Android Programming


Using Selection Widgets

 ListView
    The classic Android ListView is a plain list of text.
    However, you can have a list whose rows are made up of icons,
     or icons and text, or check-boxes and text, or whatever you
     want.
    Update Example 3.1 project




                                9
Android Programming


Using Selection Widgets




                    10
Android Programming


Using Selection Widgets

 ListView (cont.)
    Custom ArrayAdapter for binding more data
    See Example 3.2




                               11
Android Programming


Using Selection Widgets

 Example 3.2
    Custom ArrayAdapter
    Example 3.2 project
      •   MainActivity.java
      •   Person.java
      •   MyArrayAdapter.java
      •   activity_main.xml
      •   list_item.xml




                                12
Android Programming


Using Selection Widgets




                    13
Android Programming


Using Selection Widgets

                               Better.
                              Stronger.
                               Faster.




                                Using
                               convert
                                View


                    14
Android Programming


Using Selection Widgets

 GridView
    As the name suggests, GridView gives you a two-dimensional
     grid of items to choose from.

    You have moderate control over the number and size of the
     columns; the number of rows is dynamically determined based
     on the number of items the supplied adapter says are available
     for viewing.




                                15
Android Programming


Using Selection Widgets

 GridView (cont.)
    Properties
      • android:numColumns spells out how many columns there are, or, if you
        supply a value of auto_fit, Android will compute the number of columns
        based on available space and the following properties.

      • android:verticalSpacing and its counterpart android:horizontalSpacing
        indicate how much whitespace there should be between items in the grid.

      • android:columnWidth indicates how many pixels wide each column should
        be.



                                     16
Android Programming


Using Selection Widgets

 GridView (cont.)
    Properties (cont.)
       • android:stretchMode; this should be columnWidth to have the columns
         take up available space or spacingWidth to have the whitespace between
         columns absorb extra space.


    Otherwise, the GridView works much like any other selection
     widget—use setAdapter() to provide the data and child views.




                                      17
Android Programming


Using Selection Widgets

 Example 3.3
    GridView
    Example 3.3 project
       •   MainActivity.java
       •   MyArrayAdapter.java
       •   activity_main.xml
       •   gridview_item.xml




                                 18
Android Programming


Using Selection Widgets

 Spinners
    Spinners provide a quick way to select one value from a set.




                                 19
Android Programming


Using Selection Widgets

 Spinners (cont.)
    The choices you provide for the spinner can come from any
     source, but must be provided through an SpinnerAdapter, such
     as an ArrayAdapter




                               20
Android Programming


Exercise 3




             21
Android Programming

More Related Content

What's hot

Database Normalization
Database NormalizationDatabase Normalization
Database NormalizationArun Sharma
 
Chapter - 5 Data Mining Concepts and Techniques 2nd Ed slides Han & Kamber
Chapter - 5 Data Mining Concepts and Techniques 2nd Ed slides Han & KamberChapter - 5 Data Mining Concepts and Techniques 2nd Ed slides Han & Kamber
Chapter - 5 Data Mining Concepts and Techniques 2nd Ed slides Han & Kambererror007
 
10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patilwidespreadpromotion
 
Knowledge discovery process
Knowledge discovery process Knowledge discovery process
Knowledge discovery process Shuvra Ghosh
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsDrishti Bhalla
 
Normalization in SQL | Edureka
Normalization in SQL | EdurekaNormalization in SQL | Edureka
Normalization in SQL | EdurekaEdureka!
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithmNeoClassical
 
Query optimization in SQL
Query optimization in SQLQuery optimization in SQL
Query optimization in SQLAbdul Rehman
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptxSyed Zaid Irshad
 
Introduction to data structures (ss)
Introduction to data structures (ss)Introduction to data structures (ss)
Introduction to data structures (ss)Madishetty Prathibha
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm KristinaBorooah
 

What's hot (20)

Database Normalization
Database NormalizationDatabase Normalization
Database Normalization
 
Chapter - 5 Data Mining Concepts and Techniques 2nd Ed slides Han & Kamber
Chapter - 5 Data Mining Concepts and Techniques 2nd Ed slides Han & KamberChapter - 5 Data Mining Concepts and Techniques 2nd Ed slides Han & Kamber
Chapter - 5 Data Mining Concepts and Techniques 2nd Ed slides Han & Kamber
 
Web Content Mining
Web Content MiningWeb Content Mining
Web Content Mining
 
10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil10. Search Tree - Data Structures using C++ by Varsha Patil
10. Search Tree - Data Structures using C++ by Varsha Patil
 
Knowledge discovery process
Knowledge discovery process Knowledge discovery process
Knowledge discovery process
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 
Linked lists
Linked listsLinked lists
Linked lists
 
Binary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of AlgorithmsBinary Search - Design & Analysis of Algorithms
Binary Search - Design & Analysis of Algorithms
 
Normalization in SQL | Edureka
Normalization in SQL | EdurekaNormalization in SQL | Edureka
Normalization in SQL | Edureka
 
Linear search algorithm
Linear search algorithmLinear search algorithm
Linear search algorithm
 
SQL Basics
SQL BasicsSQL Basics
SQL Basics
 
Active database
Active databaseActive database
Active database
 
Database System Architectures
Database System ArchitecturesDatabase System Architectures
Database System Architectures
 
Query optimization in SQL
Query optimization in SQLQuery optimization in SQL
Query optimization in SQL
 
Data Structure and Algorithms.pptx
Data Structure and Algorithms.pptxData Structure and Algorithms.pptx
Data Structure and Algorithms.pptx
 
Graph traversals in Data Structures
Graph traversals in Data StructuresGraph traversals in Data Structures
Graph traversals in Data Structures
 
The Stack And Recursion
The Stack And RecursionThe Stack And Recursion
The Stack And Recursion
 
Introduction to data structures (ss)
Introduction to data structures (ss)Introduction to data structures (ss)
Introduction to data structures (ss)
 
Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm Linked list in Data Structure and Algorithm
Linked list in Data Structure and Algorithm
 
Linked List
Linked ListLinked List
Linked List
 

Viewers also liked

Android Tutorials - Powering with Selection Widget
Android Tutorials - Powering with Selection WidgetAndroid Tutorials - Powering with Selection Widget
Android Tutorials - Powering with Selection WidgetPrajyot Mainkar
 
[Android] Basic Widgets and Containers
[Android] Basic Widgets and Containers[Android] Basic Widgets and Containers
[Android] Basic Widgets and ContainersNikmesoft Ltd
 
[Android] Data Storage
[Android] Data Storage[Android] Data Storage
[Android] Data StorageNikmesoft Ltd
 
[iOS] Introduction to iOS Programming
[iOS] Introduction to iOS Programming[iOS] Introduction to iOS Programming
[iOS] Introduction to iOS ProgrammingNikmesoft Ltd
 
[Android] Introduction to Android Programming
[Android] Introduction to Android Programming[Android] Introduction to Android Programming
[Android] Introduction to Android ProgrammingNikmesoft Ltd
 
[Android] Intent and Activity
[Android] Intent and Activity[Android] Intent and Activity
[Android] Intent and ActivityNikmesoft Ltd
 
[Android] Widget Event Handling
[Android] Widget Event Handling[Android] Widget Event Handling
[Android] Widget Event HandlingNikmesoft Ltd
 
Introduction to Swift programming language.
Introduction to Swift programming language.Introduction to Swift programming language.
Introduction to Swift programming language.Icalia Labs
 
Mobile operating system ppt
Mobile operating system pptMobile operating system ppt
Mobile operating system pptSantosh Kumar
 

Viewers also liked (12)

Android Tutorials - Powering with Selection Widget
Android Tutorials - Powering with Selection WidgetAndroid Tutorials - Powering with Selection Widget
Android Tutorials - Powering with Selection Widget
 
[Android] Basic Widgets and Containers
[Android] Basic Widgets and Containers[Android] Basic Widgets and Containers
[Android] Basic Widgets and Containers
 
[Android] Data Storage
[Android] Data Storage[Android] Data Storage
[Android] Data Storage
 
[iOS] Introduction to iOS Programming
[iOS] Introduction to iOS Programming[iOS] Introduction to iOS Programming
[iOS] Introduction to iOS Programming
 
[iOS] Networking
[iOS] Networking[iOS] Networking
[iOS] Networking
 
Objective-C
Objective-CObjective-C
Objective-C
 
[Android] Introduction to Android Programming
[Android] Introduction to Android Programming[Android] Introduction to Android Programming
[Android] Introduction to Android Programming
 
[Android] Intent and Activity
[Android] Intent and Activity[Android] Intent and Activity
[Android] Intent and Activity
 
[Android] Widget Event Handling
[Android] Widget Event Handling[Android] Widget Event Handling
[Android] Widget Event Handling
 
Introduction to Swift programming language.
Introduction to Swift programming language.Introduction to Swift programming language.
Introduction to Swift programming language.
 
Apple iOS
Apple iOSApple iOS
Apple iOS
 
Mobile operating system ppt
Mobile operating system pptMobile operating system ppt
Mobile operating system ppt
 

Similar to [Android] Using Selection Widgets

Training Session 2 - Day 2
Training Session 2 - Day 2Training Session 2 - Day 2
Training Session 2 - Day 2Vivek Bhusal
 
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]Nehil Jain
 
[Android] Maps, Geocoding and Location-Based Services
[Android] Maps, Geocoding and Location-Based Services[Android] Maps, Geocoding and Location-Based Services
[Android] Maps, Geocoding and Location-Based ServicesNikmesoft Ltd
 
[Android] 2D Graphics
[Android] 2D Graphics[Android] 2D Graphics
[Android] 2D GraphicsNikmesoft Ltd
 
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROIDMaterial Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROIDJordan Open Source Association
 
AndroidX Google Extended I/O BKK 2018
AndroidX Google Extended I/O BKK 2018 AndroidX Google Extended I/O BKK 2018
AndroidX Google Extended I/O BKK 2018 Theerasan Tonthongkam
 
Interface Programming Android
Interface Programming AndroidInterface Programming Android
Interface Programming AndroidMaksym Davydov
 
UI controls in Android
UI controls in Android UI controls in Android
UI controls in Android DivyaKS12
 
Android interview questions and answers
Android interview questions and answersAndroid interview questions and answers
Android interview questions and answerskavinilavuG
 
15 android libraries for app development
15 android libraries for app development15 android libraries for app development
15 android libraries for app developmentConcetto Labs
 
Android 101 - Introduction to Android Development
Android 101 - Introduction to Android DevelopmentAndroid 101 - Introduction to Android Development
Android 101 - Introduction to Android DevelopmentAndy Scherzinger
 
Ii 1300-java essentials for android
Ii 1300-java essentials for androidIi 1300-java essentials for android
Ii 1300-java essentials for androidAdrian Mikeliunas
 
Mobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfMobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfAbdullahMunir32
 
Step by Step Asp.Net GridView Tutorials
Step by Step Asp.Net GridView TutorialsStep by Step Asp.Net GridView Tutorials
Step by Step Asp.Net GridView TutorialsNilesh kumar Jadav
 
[Android] Multiple Background Threads
[Android] Multiple Background Threads[Android] Multiple Background Threads
[Android] Multiple Background ThreadsNikmesoft Ltd
 
Adapter and cache technique
Adapter and cache techniqueAdapter and cache technique
Adapter and cache techniqueHoang Vy Nguyen
 

Similar to [Android] Using Selection Widgets (20)

Training Session 2 - Day 2
Training Session 2 - Day 2Training Session 2 - Day 2
Training Session 2 - Day 2
 
Android Introduction
Android IntroductionAndroid Introduction
Android Introduction
 
Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]Lecture Slides for List Views [Android ]
Lecture Slides for List Views [Android ]
 
Android overview
Android overviewAndroid overview
Android overview
 
[Android] Maps, Geocoding and Location-Based Services
[Android] Maps, Geocoding and Location-Based Services[Android] Maps, Geocoding and Location-Based Services
[Android] Maps, Geocoding and Location-Based Services
 
[Android] 2D Graphics
[Android] 2D Graphics[Android] 2D Graphics
[Android] 2D Graphics
 
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROIDMaterial Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
Material Design (The Technical Essentials) by Mohammad Aljobairi @AMMxDROID
 
Android Materials Design
Android Materials Design Android Materials Design
Android Materials Design
 
AndroidX Google Extended I/O BKK 2018
AndroidX Google Extended I/O BKK 2018 AndroidX Google Extended I/O BKK 2018
AndroidX Google Extended I/O BKK 2018
 
Interface Programming Android
Interface Programming AndroidInterface Programming Android
Interface Programming Android
 
UI controls in Android
UI controls in Android UI controls in Android
UI controls in Android
 
Android interview questions and answers
Android interview questions and answersAndroid interview questions and answers
Android interview questions and answers
 
15 android libraries for app development
15 android libraries for app development15 android libraries for app development
15 android libraries for app development
 
Android 101 - Introduction to Android Development
Android 101 - Introduction to Android DevelopmentAndroid 101 - Introduction to Android Development
Android 101 - Introduction to Android Development
 
Ii 1300-java essentials for android
Ii 1300-java essentials for androidIi 1300-java essentials for android
Ii 1300-java essentials for android
 
Mobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdfMobile Application Development -Lecture 09 & 10.pdf
Mobile Application Development -Lecture 09 & 10.pdf
 
Step by Step Asp.Net GridView Tutorials
Step by Step Asp.Net GridView TutorialsStep by Step Asp.Net GridView Tutorials
Step by Step Asp.Net GridView Tutorials
 
[Android] Multiple Background Threads
[Android] Multiple Background Threads[Android] Multiple Background Threads
[Android] Multiple Background Threads
 
Adapter and cache technique
Adapter and cache techniqueAdapter and cache technique
Adapter and cache technique
 
Android
AndroidAndroid
Android
 

More from Nikmesoft Ltd

[iOS] Multiple Background Threads
[iOS] Multiple Background Threads[iOS] Multiple Background Threads
[iOS] Multiple Background ThreadsNikmesoft Ltd
 
[iOS] Basic UI Elements
[iOS] Basic UI Elements[iOS] Basic UI Elements
[iOS] Basic UI ElementsNikmesoft Ltd
 
[Android] Multimedia Programming
[Android] Multimedia Programming[Android] Multimedia Programming
[Android] Multimedia ProgrammingNikmesoft Ltd
 
[Android] Android Animation
[Android] Android Animation[Android] Android Animation
[Android] Android AnimationNikmesoft Ltd
 
[Android] Services and Broadcast Receivers
[Android] Services and Broadcast Receivers[Android] Services and Broadcast Receivers
[Android] Services and Broadcast ReceiversNikmesoft Ltd
 
[Android] Web services
[Android] Web services[Android] Web services
[Android] Web servicesNikmesoft Ltd
 

More from Nikmesoft Ltd (8)

[iOS] Data Storage
[iOS] Data Storage[iOS] Data Storage
[iOS] Data Storage
 
[iOS] Multiple Background Threads
[iOS] Multiple Background Threads[iOS] Multiple Background Threads
[iOS] Multiple Background Threads
 
[iOS] Navigation
[iOS] Navigation[iOS] Navigation
[iOS] Navigation
 
[iOS] Basic UI Elements
[iOS] Basic UI Elements[iOS] Basic UI Elements
[iOS] Basic UI Elements
 
[Android] Multimedia Programming
[Android] Multimedia Programming[Android] Multimedia Programming
[Android] Multimedia Programming
 
[Android] Android Animation
[Android] Android Animation[Android] Android Animation
[Android] Android Animation
 
[Android] Services and Broadcast Receivers
[Android] Services and Broadcast Receivers[Android] Services and Broadcast Receivers
[Android] Services and Broadcast Receivers
 
[Android] Web services
[Android] Web services[Android] Web services
[Android] Web services
 

[Android] Using Selection Widgets