> For the complete documentation index, see [llms.txt](https://android-course.cornellappdev.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://android-course.cornellappdev.com/archive/archived-native-android-textbook-pages/5.-listviews/4.2-recyclerview.md).

# 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`.&#x20;

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.&#x20;

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.&#x20;

{% code title="main\_activity.xml" %}

```markup
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="fill_parent"
android:layout_height="fill_parent"
android:orientation="vertical" >
    <ListView
        android:id="@+id/list"
        android:layout_width="fill_parent"
        android:layout_height="wrap_content" >
    </ListView>
</LinearLayout>
```

{% endcode %}

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.&#x20;

{% code title="MainActivity.kt" %}

```kotlin
class MainActivity : AppCompatActivity() {

  private var mainListView : ListView = null
  private var listAdapter : ArrayAdapter<String> = null

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    setContentView(R.layout.main_activity)
    
    var mainListView = findViewById<ListView>(R.id.userlist)
    
    // Creating our list of menu items
    var menuList = 
      arrayOf("Starbucks Coffee", "Tazo Tea", "Hot Cocoa", "Smoothies")

    // Creating an ArrayAdapter
    listAdapter = ArrayAdapter(
        this, 
        android.R.layout.simple_list_item_1, // built-in layout for list items
        menuList
      )
      
    // Setting the adapter to the list view
    mainListView.adapter = listAdapter
  }
}
```

{% endcode %}

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.&#x20;


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://android-course.cornellappdev.com/archive/archived-native-android-textbook-pages/5.-listviews/4.2-recyclerview.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
