SlideShare uma empresa Scribd logo
1 de 16
AdapterView
& Adapters
Android Training
By Khaled Anaqwa
AdapterView





The AdapterView is a ViewGroup subclass
whose child Views are determined by an
Adapter that binds AdapterView object to
data of some type.
Typically you are going to use subsclasses of
AdapterView class instead of using it directly
Example subclasses of AdapterView class




ListView
Spinner
Gallery
Adapter
 You

can populate an AdapterView such
as ListView or GridView by binding the
AdapterView instance to an Adapter,
which retrieves data from an external
source and creates a View that
represents each data entry.
AdapterView & Adapters
So
 The

Adapter provides access to the data
items.
 The Adapter is also responsible for making
a View for each item in the data set.
 Types of Adatpers - they implements
ListAdatper interface




ArrayAdatper
CursorAdatper
There are a few more
Adapter Class Hierarchy
 BaseAdatper

abstract class implements
ListAdapter and SpinnerAdatper
interfaces
 ArrayAdapter and CursorAdapter classes
are subclasses of BaseAdapter class
AdapterView Responsibilities
 Two



main responsibilities of AdapterView

Filling the layout with data (with a help from
Adapter)
Handling user selections - when a user
selects an item, perform some action
 AdapterView.OnItemClickListener
 AdapterView.OnItemLongClickListener
 AdapterView.OnItemSelectedListener
ListActivity








Android-provided class specially designed for
displaying a list of items by binding to a data
source such as an array or Cursor, and exposes
event handlers when the user selects an item.
ListActivity hosts a ListView object that can be
bound through an adatper to different data
sources, typically either an array or a Cursor
holding query results.
setListAdapter(ListAdatper adapter) method
automatically creates ListView object from the
ListAdapter object
Has a default layout that consists of a single, fullscreen list in the center of the screen
Example
 List

of COUNTRIES
 Notice

that this does not load a layout file
for the Activity (which you usually do with
setContentView(int)).
 setListAdapter(ListAdapter) automatically
adds a ListView to fill the entire screen of
the ListActivity.
What is the difference
between a ListView and a
ScrollView ?
Simply
 ScrollView

a host for “static” content and
a ListView a host for “dynamic” content.
Listview
 ListView

is a view group that displays a list
of scrollable items. The list items are
automatically inserted to the list using an
Adapter that pulls content from a source
such as an array or database query and
converts each item result into a view
that's placed into the list.
Spinner
A

view that displays one child at a time
and lets the user pick among them.
 The items in the Spinner come from the
Adapter associated with this view.
Example
 Choose

one of COUNTRIES
In ArrayAdapter


Data updates





The ArrayAdapter class allows to remove all
elements in its underlying data structure with the
clear() method call.
You can then add new elements via the add()
method or a Collection via the addAll() method.
You can also directly modify the underlying data
structure and call the notifyDataSetChanged()
method on the adapter to notify him about the
changes in data.

Mais conteúdo relacionado

Mais procurados (10)

List adapter with multiple objects
List adapter with multiple objectsList adapter with multiple objects
List adapter with multiple objects
 
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
 
Isotope.js
Isotope.jsIsotope.js
Isotope.js
 
Creating EPiServer Usage Reports
Creating EPiServer Usage ReportsCreating EPiServer Usage Reports
Creating EPiServer Usage Reports
 
Android App Development - 04 Views and layouts
Android App Development - 04 Views and layoutsAndroid App Development - 04 Views and layouts
Android App Development - 04 Views and layouts
 
AutocompleteTextView And MultiAutoCompleteTextView
AutocompleteTextView And MultiAutoCompleteTextViewAutocompleteTextView And MultiAutoCompleteTextView
AutocompleteTextView And MultiAutoCompleteTextView
 
2310 b xc
2310 b xc2310 b xc
2310 b xc
 
Search syntax training
Search syntax trainingSearch syntax training
Search syntax training
 
Adrotator in asp
Adrotator in aspAdrotator in asp
Adrotator in asp
 
ASP.net Image Slideshow
ASP.net Image SlideshowASP.net Image Slideshow
ASP.net Image Slideshow
 

Destaque

Content providers in Android
Content providers in AndroidContent providers in Android
Content providers in Android
Alexey Ustenko
 
android design pattern
android design patternandroid design pattern
android design pattern
Lucas Xu
 
Adapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListViewAdapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListView
Yuki Anzai
 
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
 

Destaque (19)

Android development - ListView & Adapter
Android development - ListView & AdapterAndroid development - ListView & Adapter
Android development - ListView & Adapter
 
Android tutorial points
Android tutorial pointsAndroid tutorial points
Android tutorial points
 
Android Training - View Pager
Android Training - View PagerAndroid Training - View Pager
Android Training - View Pager
 
Adapter and cache technique
Adapter and cache techniqueAdapter and cache technique
Adapter and cache technique
 
Android sync adapter
Android sync adapterAndroid sync adapter
Android sync adapter
 
Android ui part 2
Android ui part 2Android ui part 2
Android ui part 2
 
Android content providers
Android content providersAndroid content providers
Android content providers
 
Android Session 6 - UI Part 1
Android Session 6 - UI Part 1Android Session 6 - UI Part 1
Android Session 6 - UI Part 1
 
Android Custom view
Android Custom view Android Custom view
Android Custom view
 
Journey of an event, the android touch - Marco Cova, Facebook
Journey of an event, the android touch - Marco Cova, FacebookJourney of an event, the android touch - Marco Cova, Facebook
Journey of an event, the android touch - Marco Cova, Facebook
 
Content providers in Android
Content providers in AndroidContent providers in Android
Content providers in Android
 
Fun with RecyclerView
Fun with RecyclerViewFun with RecyclerView
Fun with RecyclerView
 
Tech Talk #2: Android app performance tips
Tech Talk #2: Android app performance tipsTech Talk #2: Android app performance tips
Tech Talk #2: Android app performance tips
 
Recyclerview in action
Recyclerview in action Recyclerview in action
Recyclerview in action
 
android design pattern
android design patternandroid design pattern
android design pattern
 
Bonnes pratiques développement android
Bonnes pratiques développement androidBonnes pratiques développement android
Bonnes pratiques développement android
 
Adapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListViewAdapter & ListView & ExpandalbeListView
Adapter & ListView & ExpandalbeListView
 
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]
 
Mastering RecyclerView Layouts
Mastering RecyclerView LayoutsMastering RecyclerView Layouts
Mastering RecyclerView Layouts
 

Semelhante a Android Training (AdapterView & Adapter)

Grid View- GridView is a ViewGroup that displays items in a two d.pdf
Grid View- GridView is a ViewGroup that displays items in a two d.pdfGrid View- GridView is a ViewGroup that displays items in a two d.pdf
Grid View- GridView is a ViewGroup that displays items in a two d.pdf
deepua8
 
Day 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViewsDay 8: Dealing with Lists and ListViews
Day 8: Dealing with Lists and ListViews
Ahsanul Karim
 
Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_list
Vlad Kolesnyk
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
ssuseredfbe9
 
View groups containers
View groups containersView groups containers
View groups containers
Mani Selvaraj
 

Semelhante a Android Training (AdapterView & Adapter) (20)

Grid View- GridView is a ViewGroup that displays items in a two d.pdf
Grid View- GridView is a ViewGroup that displays items in a two d.pdfGrid View- GridView is a ViewGroup that displays items in a two d.pdf
Grid View- GridView is a ViewGroup that displays items in a two d.pdf
 
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 5 android app code advancement
Day 5  android app code advancementDay 5  android app code advancement
Day 5 android app code advancement
 
Lab2-android
Lab2-androidLab2-android
Lab2-android
 
ListView RecyclerView.pptx
ListView RecyclerView.pptxListView RecyclerView.pptx
ListView RecyclerView.pptx
 
Android UI
Android UI Android UI
Android UI
 
Android Ui
Android UiAndroid Ui
Android Ui
 
Hello Android
Hello AndroidHello Android
Hello Android
 
Android Training Session 1
Android Training Session 1Android Training Session 1
Android Training Session 1
 
Session 2- day 3
Session 2- day 3Session 2- day 3
Session 2- day 3
 
Android tutorials8 todo_list
Android tutorials8 todo_listAndroid tutorials8 todo_list
Android tutorials8 todo_list
 
04 user interfaces
04 user interfaces04 user interfaces
04 user interfaces
 
Murach: How to transfer data from controllers
Murach: How to transfer data from controllersMurach: How to transfer data from controllers
Murach: How to transfer data from controllers
 
oop lecture framework,list,maps,collection
oop lecture framework,list,maps,collectionoop lecture framework,list,maps,collection
oop lecture framework,list,maps,collection
 
List view3
List view3List view3
List view3
 
Android development session 3 - layout
Android development   session 3 - layoutAndroid development   session 3 - layout
Android development session 3 - layout
 
How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)How to become an Android dev starting from iOS (and vice versa)
How to become an Android dev starting from iOS (and vice versa)
 
List view1
List view1List view1
List view1
 
View groups containers
View groups containersView groups containers
View groups containers
 
TKU行動APP開發管理實務 - ListView & Custom Adapter
TKU行動APP開發管理實務 - ListView & Custom AdapterTKU行動APP開發管理實務 - ListView & Custom Adapter
TKU行動APP開發管理實務 - ListView & Custom Adapter
 

Mais de Khaled Anaqwa

Android Training (Intro)
Android Training (Intro)Android Training (Intro)
Android Training (Intro)
Khaled Anaqwa
 

Mais de Khaled Anaqwa (16)

Android Training (Storing & Shared Preferences)
Android Training (Storing & Shared Preferences)Android Training (Storing & Shared Preferences)
Android Training (Storing & Shared Preferences)
 
Android Training (Content Provider)
Android Training (Content Provider)Android Training (Content Provider)
Android Training (Content Provider)
 
Android Training (Services)
Android Training (Services)Android Training (Services)
Android Training (Services)
 
Android Training (Notifications)
Android Training (Notifications)Android Training (Notifications)
Android Training (Notifications)
 
Android Training (Broadcast Receiver)
Android Training (Broadcast Receiver)Android Training (Broadcast Receiver)
Android Training (Broadcast Receiver)
 
Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)Android Training (Storing data using SQLite)
Android Training (Storing data using SQLite)
 
Android Training (Animation)
Android Training (Animation)Android Training (Animation)
Android Training (Animation)
 
Android Training (Touch)
Android Training (Touch)Android Training (Touch)
Android Training (Touch)
 
Android Training (Sensors)
Android Training (Sensors)Android Training (Sensors)
Android Training (Sensors)
 
Android Training (Media)
Android Training (Media)Android Training (Media)
Android Training (Media)
 
Android Training (ScrollView , Horizontal ScrollView WebView)
Android Training (ScrollView , Horizontal ScrollView  WebView)Android Training (ScrollView , Horizontal ScrollView  WebView)
Android Training (ScrollView , Horizontal ScrollView WebView)
 
Android training (android style)
Android training (android style)Android training (android style)
Android training (android style)
 
Android Training (Android UI)
Android Training (Android UI)Android Training (Android UI)
Android Training (Android UI)
 
Android Training (Intro)
Android Training (Intro)Android Training (Intro)
Android Training (Intro)
 
Android Training (Java Review)
Android Training (Java Review)Android Training (Java Review)
Android Training (Java Review)
 
Android Training (android fundamental)
Android Training (android fundamental)Android Training (android fundamental)
Android Training (android fundamental)
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
Joaquim Jorge
 

Último (20)

ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemkeProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
ProductAnonymous-April2024-WinProductDiscovery-MelissaKlemke
 
Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024Manulife - Insurer Innovation Award 2024
Manulife - Insurer Innovation Award 2024
 
GenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdfGenAI Risks & Security Meetup 01052024.pdf
GenAI Risks & Security Meetup 01052024.pdf
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Artificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : UncertaintyArtificial Intelligence Chap.5 : Uncertainty
Artificial Intelligence Chap.5 : Uncertainty
 
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live StreamsTop 5 Benefits OF Using Muvi Live Paywall For Live Streams
Top 5 Benefits OF Using Muvi Live Paywall For Live Streams
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
 
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, AdobeApidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
Apidays New York 2024 - Scaling API-first by Ian Reasor and Radu Cotescu, Adobe
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Artificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and MythsArtificial Intelligence: Facts and Myths
Artificial Intelligence: Facts and Myths
 
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
Deploy with confidence: VMware Cloud Foundation 5.1 on next gen Dell PowerEdg...
 
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost SavingRepurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
Repurposing LNG terminals for Hydrogen Ammonia: Feasibility and Cost Saving
 
Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024Tata AIG General Insurance Company - Insurer Innovation Award 2024
Tata AIG General Insurance Company - Insurer Innovation Award 2024
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 

Android Training (AdapterView & Adapter)

  • 2. AdapterView    The AdapterView is a ViewGroup subclass whose child Views are determined by an Adapter that binds AdapterView object to data of some type. Typically you are going to use subsclasses of AdapterView class instead of using it directly Example subclasses of AdapterView class    ListView Spinner Gallery
  • 3. Adapter  You can populate an AdapterView such as ListView or GridView by binding the AdapterView instance to an Adapter, which retrieves data from an external source and creates a View that represents each data entry.
  • 5. So  The Adapter provides access to the data items.  The Adapter is also responsible for making a View for each item in the data set.  Types of Adatpers - they implements ListAdatper interface    ArrayAdatper CursorAdatper There are a few more
  • 6. Adapter Class Hierarchy  BaseAdatper abstract class implements ListAdapter and SpinnerAdatper interfaces  ArrayAdapter and CursorAdapter classes are subclasses of BaseAdapter class
  • 7. AdapterView Responsibilities  Two   main responsibilities of AdapterView Filling the layout with data (with a help from Adapter) Handling user selections - when a user selects an item, perform some action  AdapterView.OnItemClickListener  AdapterView.OnItemLongClickListener  AdapterView.OnItemSelectedListener
  • 8. ListActivity     Android-provided class specially designed for displaying a list of items by binding to a data source such as an array or Cursor, and exposes event handlers when the user selects an item. ListActivity hosts a ListView object that can be bound through an adatper to different data sources, typically either an array or a Cursor holding query results. setListAdapter(ListAdatper adapter) method automatically creates ListView object from the ListAdapter object Has a default layout that consists of a single, fullscreen list in the center of the screen
  • 10.  Notice that this does not load a layout file for the Activity (which you usually do with setContentView(int)).  setListAdapter(ListAdapter) automatically adds a ListView to fill the entire screen of the ListActivity.
  • 11. What is the difference between a ListView and a ScrollView ?
  • 12. Simply  ScrollView a host for “static” content and a ListView a host for “dynamic” content.
  • 13. Listview  ListView is a view group that displays a list of scrollable items. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database query and converts each item result into a view that's placed into the list.
  • 14. Spinner A view that displays one child at a time and lets the user pick among them.  The items in the Spinner come from the Adapter associated with this view.
  • 16. In ArrayAdapter  Data updates    The ArrayAdapter class allows to remove all elements in its underlying data structure with the clear() method call. You can then add new elements via the add() method or a Collection via the addAll() method. You can also directly modify the underlying data structure and call the notifyDataSetChanged() method on the adapter to notify him about the changes in data.

Notas do Editor

  1. public class HelloListView extends ListActivity { static final String[] COUNTRIES = new String[] { ”Palestine", ”Jordan", ”Sudan", ”Egypt" }; /** Called when the activity is first created. */ @Overridepublic void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); // Create an adapterArrayAdapter<String> arrayAdapter = new ArrayAdapter<String>( this, // Application contextR.layout.list_item, // layout description for each list item COUNTRIES); // String array of countries defined setListAdapter(arrayAdapter); }}
  2. For example, you may use a ScrollView to display a graphical user interface larger then the actual screen. The GUI is static in the sense that its content will never change, and the reason to use a ScrollView is to access all the widgets on the GUI. On the other hand consider the contacts list on your android phone, if you access it you will get a list of contacts, if you delete a contact and reopen it, you will get a different list of contacts. For that reason the ListView displays dynamic content.
  3. public class MyAndroidAppActivity extends Activity { private Spinner spinner1; @Override public void onCreate(Bundle savedInstanceState) {super.onCreate(savedInstanceState);setContentView(R.layout.main);static final String[] COUNTRIES = new String[] { ”Palestine", ”Jordan", ”Sudan", ”Egypt" };spinner1 = (Spinner) findViewById(R.id.spinner1);ArrayAdapter<String> dataAdapter = new ArrayAdapter<String>(this,android.R.layout.simple_spinner_item, COUNTRIES );dataAdapter.setDropDownViewResource(android.R.layout.simple_spinner_dropdown_item);spinner.setAdapter(dataAdapter); }}