Adapters in android are the one who retrieve data from a data source such as an array, database, file etc and provide it to AdapterView's such as ListView, GridView etc. AdapterView is something that displays data given by Adapters.Basically an Adapter manages the data to be displayed in a AdapterView effectively.
Adapters are made in Android to make things easy and to do our job faster. For example if we take the case of one of the AdapterView that is a ListView, ListView is something which shows a list of items, to show a ListView without Adapters we want to write extra code that do functions like creating a list of TextViews that can be Scrolled means must be inside a ScrollView,also Adapters manages the index when user Scrolls down and to identify the click event on each of the TextView's in it, also Adapter implements pagination concepts for the contents. So we are lucky that Android's Adapter will manage all of these tasks for you in the background.
How Adapter manages all these tasks? What is AdapterView?
Lets explain it easily,Lets say we have a data source let it be an array, database or whatever data source ,then the adapter takes the data and creates a View out of it, then this View is given to someone called an AdapterView. The AdapterView Displays the data neatly on the screen.Basically what an AdapterView is it Contains lot of repeated views that display data.Adapter is responsible only for taking the data or managing the data while the AdapterView is responsible for controlling how the data is being displayed.We can take data from an array, a database etc so according to that there are different types of Adapters such as ArrayAdapter, SimpleCursorAdapter, BaseAdapter etc. ArrayAdapter takes data from an array while SimpleCursorAdapter takes data from a database, while BaseAdapter is a custom adapter which can be customized to how data can be extracted, processed and how the view should be generated.Also according to the type of display there are different AdapterView's such as ListView,GridView,Gallery,Spinner respectively that can display data vertically in a list, along rows and columns, horizontally, or in a drop down menu.Note Gallery is deprecated as of Android 4.1.
0 comments:
Post a Comment