3.3 Implementation of a ListView
While list views are not generally recommended, there will be situations where implementing a list view will save time and reduce file size. List views are used for small lists where the list is not expected to extend past the screen or when the individual cells in the list have simple layouts, like just a TextView
.
For example, we used a list view to show the menu items of a specific eatery because the list of menu items is relatively short and does not require complex layouts.
In our example, we'll be creating a simple list that displays the menu items of Libe Cafe. We'll start by adding a ListView
to the XML.
Then we'll be using an Android supported adapter for the list view called ArrayAdapter
, which takes in an array and displays it directly in list form.
In the example above, you'll notice that you don't need many lines of code to create and populate a simple ListView
which is why ListView
s are viable solutions for simple views. As you will learn in the next section, creating a recycler view list will require more classes and more operations.
Last updated