4.7 ListView
4.7 ListView
-Adapter and Adapter View are so popular, that every time you see any app with a List of items or Grid of items,
you can say for sure that it is using Adapter and Adapter View.
-Generally, when we create any List or Grid of data, we think we can use a loop to iterate over the data and then set
the data to create the list or grid. But consume a lot of time, making the app slow
• What is an Adapter?
-An adapter acts like a bridge between a data source and the user interface. It reads data from various data
sources, coverts it into View objects and provide it to the linked Adapter view to create UI components.
The data source or dataset can be an Array object, a List object etc.
• What is an Adapter View?
An Adapter View can be used to display large sets of data efficiently in form of List or Grid etc, provided to it by an
Adapter.
Suppose you have a dataset, like a String array with the following contents.
Now, what does an Adapter do is that it takes the data from this array and creates a View from this data and then, it gives this
View to an AdapterView. The AdapterView then displays the data in the way you want.
ListView
-List of scrollable items can be displayed in Android using ListView.
-It helps you to displaying the data in the form of a scrollable list.
Adapter: To fill the data in a ListView we simply use adapters. List items are automatically inserted to a list using an Adapter
that pulls the content from a source such as an arraylist, array or database.
Example-
<ListView
android:id="@+id/mobile_list"
android:layout_width="match_parent"
android:layout_height="wrap_content" >
</ListView>
Attributes of ListView:-
1. id: id is used to uniquely identify a ListView.