This example shows a ListView displaying a list of countries. We start by creating a new Android project and defining our layout file that will be used in the sample program.
Layout XML File
This is created by first creating an xml for layout file named list_country.xml. The xml file just contains the generic layout for our list. The list_country.xml file should be saved in /res/layout/ under the current project folders. Below is the contents of the list_country.xml file:
Below is the source code of the program. We name the program as HelloListViewActivity.java.
In the program, make sure you import the following components:
These will be needed by the program lines that is accessing the methods that belongs to the above components.