android training (adapterview & adapter)
DESCRIPTION
Android Training (AdapterView & Adapter)TRANSCRIPT
![Page 1: Android Training (AdapterView & Adapter)](https://reader035.vdocuments.mx/reader035/viewer/2022070316/555ac778d8b42a761a8b4edc/html5/thumbnails/1.jpg)
AdapterView & Adapters Android Training
By Khaled Anaqwa
![Page 2: Android Training (AdapterView & Adapter)](https://reader035.vdocuments.mx/reader035/viewer/2022070316/555ac778d8b42a761a8b4edc/html5/thumbnails/2.jpg)
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
![Page 3: Android Training (AdapterView & Adapter)](https://reader035.vdocuments.mx/reader035/viewer/2022070316/555ac778d8b42a761a8b4edc/html5/thumbnails/3.jpg)
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.
![Page 4: Android Training (AdapterView & Adapter)](https://reader035.vdocuments.mx/reader035/viewer/2022070316/555ac778d8b42a761a8b4edc/html5/thumbnails/4.jpg)
AdapterView & Adapters
![Page 5: Android Training (AdapterView & Adapter)](https://reader035.vdocuments.mx/reader035/viewer/2022070316/555ac778d8b42a761a8b4edc/html5/thumbnails/5.jpg)
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
![Page 6: Android Training (AdapterView & Adapter)](https://reader035.vdocuments.mx/reader035/viewer/2022070316/555ac778d8b42a761a8b4edc/html5/thumbnails/6.jpg)
Adapter Class Hierarchy BaseAdatper abstract class implements
ListAdapter and SpinnerAdatper interfaces
ArrayAdapter and CursorAdapter classes are subclasses of BaseAdapter class
![Page 7: Android Training (AdapterView & Adapter)](https://reader035.vdocuments.mx/reader035/viewer/2022070316/555ac778d8b42a761a8b4edc/html5/thumbnails/7.jpg)
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
![Page 8: Android Training (AdapterView & Adapter)](https://reader035.vdocuments.mx/reader035/viewer/2022070316/555ac778d8b42a761a8b4edc/html5/thumbnails/8.jpg)
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, full-screen list in the center of the screen
![Page 9: Android Training (AdapterView & Adapter)](https://reader035.vdocuments.mx/reader035/viewer/2022070316/555ac778d8b42a761a8b4edc/html5/thumbnails/9.jpg)
Example List of COUNTRIES
![Page 10: Android Training (AdapterView & Adapter)](https://reader035.vdocuments.mx/reader035/viewer/2022070316/555ac778d8b42a761a8b4edc/html5/thumbnails/10.jpg)
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.
![Page 11: Android Training (AdapterView & Adapter)](https://reader035.vdocuments.mx/reader035/viewer/2022070316/555ac778d8b42a761a8b4edc/html5/thumbnails/11.jpg)
What is the difference between a ListView and a ScrollView ?
![Page 12: Android Training (AdapterView & Adapter)](https://reader035.vdocuments.mx/reader035/viewer/2022070316/555ac778d8b42a761a8b4edc/html5/thumbnails/12.jpg)
Simply ScrollView a host for “static” content
and a ListView a host for “dynamic” content.
![Page 13: Android Training (AdapterView & Adapter)](https://reader035.vdocuments.mx/reader035/viewer/2022070316/555ac778d8b42a761a8b4edc/html5/thumbnails/13.jpg)
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.
![Page 14: Android Training (AdapterView & Adapter)](https://reader035.vdocuments.mx/reader035/viewer/2022070316/555ac778d8b42a761a8b4edc/html5/thumbnails/14.jpg)
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.
![Page 15: Android Training (AdapterView & Adapter)](https://reader035.vdocuments.mx/reader035/viewer/2022070316/555ac778d8b42a761a8b4edc/html5/thumbnails/15.jpg)
Example Choose one of COUNTRIES
![Page 16: Android Training (AdapterView & Adapter)](https://reader035.vdocuments.mx/reader035/viewer/2022070316/555ac778d8b42a761a8b4edc/html5/thumbnails/16.jpg)
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.