Android Simple ListView Tutorial with Example

Android Simple ListView Tutorial with Example

ListView is a group of views which will display a list of scrollable items. The list items will be automatically inserted to the list using an Adapter. The adapter will pull 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.
There are 2 types of adapter
1: ArrayAdapter which takes input as an array
2: CursorAdapter which exposes data from Cursor in SqliteDatabase

We can also make our customadapter which should extend BaseAdapter

Android Simple ListView

  1. Create a new application in Android Studio
  2. Create an empty activity named ( and its corresponding layout file (activity_main.xml)
  3. In activity_main.xml, create a ListView and specify an id to it as follows

  4. Create an array in MainActivity class, let’s say

  5. ListView is a group/list of similar kind of views. We will create a listelement to show the food items. Right click on res/layout -> New -> Layout resource file. Name it “list_element”. Add a textView to it

  6. Now to show the data in the listView, we need to use adapter class. There are many adapters available. Here,we will be using

    Android Simple Listview

  7. Show separation lines of list element in listView. Add these two lines to ListView XML

    Android Simple listview with divider
  8. To get the value of element click we will use OnItemClickListener

    View post on

Leave a Reply

Your email address will not be published. Required fields are marked *