Android ListView

Android ListView

What is ListView?

Android ListView is a view which groups several items and display them in vertical scrollable list. The list items are automatically inserted to the list using an Adapter that pulls content from a source such as an array or database.

An adapter actually bridges between UI components and the data source that fill data into UI Component. Adapter can be used to supply the data to like spinner, list view, grid view etc.

Example

In this example i will be demonstrating how to build simple android ListView and Custom ListView. This article is about creating simple ListView with textViews and CustomListView with textViews and Images.

VIDEO DEMO

Let’s get start by creating a project in Eclipse IDE.

Simple ListView

1. Create a new project in Eclipse by navigating to File ⇒ New Android ⇒ Application Project and fill required details. (I kept my main activity name as MainActivity.java)

2. Open your your AndroidManifest.xml file and make your “MainActivity” as Launcher activity.

3. Create a layout file for MainActivtiy.java under res ⇒ layout folder. I named the layout file as activity_main.xml. This will be your first launching activity layout.

4. Add the following code in MainActivity.java activity. In this following code we make a ArrayList and use Adapter for manages the data model and adapts it to the individual entries in the widget.

5. Run the application and you will get the output as shown in video.

Custom ListView

1. Create a new project in Eclipse by navigating to File ⇒ New Android ⇒ Application Project and fill required details. (I kept my main activity name as MainActivity.java)

2. Open your your AndroidManifest.xml file and make your  MainActivity as Launcher activity.

3. Create a layout file for MainActivtiy.java under res ⇒ layout folder. I named the layout file as activity_main.xml. This will be your first launching activity layout.

4. Create a layout file for custom views for listview under res ⇒ layout folder. I named the layout file as custom.xml. This will be your custom layout for listview.

5. Create a Items.java class for setting and getting listview items from it. This class works as getter and setter for listview items.

6. Create a CustomAdapter.java class for custom listview adapter for inflating custom view over listView.

7. Add the following code in MainActivity.java activity. In this following code we learn how to use custom adapter in listview and set custom listview over adapter.

8. Run the application and you will get the output as shown in video and you are done.

Thanks. 🙂

Download Source Code for both Projects – >

 

 

Leave a Comment

Comment (required)

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code class="" title="" data-url=""> <del datetime=""> <em> <i> <q cite=""> <s> <strike> <strong> <pre class="" title="" data-url=""> <span class="" title="" data-url="">

Name (required)
Email (required)