Android ListView Tutorial

Android ListView is very important in the android application to showing a list of item in the screen. It defined as a view group that displays a list of scrollable items. You do not need to implement a scrollView in the android listView because it was officially built-in the scrollView capabilities. The Android ListView items is inserted using an Adapter that get content from the database or an array convert into a view. Besides, It is also a popular widget to be used in the android.

In this Tutorial, I will teach you some steps to implement a simple ListView in android studio.

Creating a New Project

1. Open Android Studio IDE in your computer.
2. Create a new project and Edit the Application name to “ListViewExample”.
(Optional) You can edit the company domain or select the suitable location for current project tutorial. Then click next button to proceed.
3. Select Minimum SDK (API 15:Android 4.0.3 (IceCreamSandwich). I choose the API 15 because many android devices currently are support more than API 15. Click Next button.
4. Choose “Empty Project” and Click Next button
5. Lastly, press finish button.

Add a new Class

Go to your package name folder and right click create a new java class , name it as MyListAdapter. Android listview picture 1

Edit MyListAdapter.java

This class should extends to baseAdapter so that you can get methods from the baseAdapter.

int getCount() – It represent by the Adapter carry how many item in the data set.

Object getItem(int) – It can use for getting the data set item by specify the position.

long getItemId(int) – It use for getting the row id of the data set item by specify the position.

View getView(int,View,ViewGroup)– It can get a view that display the data at the specific position.

Edit activity_main.xml Layout

Go to your activity_main.xml and insert the ListView layout.

Edit MainActivity.java

In your MainActivity.java, add the following code set MyListAdapter to your listView.

Run your Project

Now, you can run this project in your emulator or android device. You can see the ListView is showing the items.

(Android ListView)

Source Code

[sociallocker][/sociallocker]
(Visited 362 times, 1 visits today)
Advertisements

Kristofer Ng

A crazy android and web developer. Passion on developing android application and exploring new technology as a hobby.

You may also like...

Leave a Reply

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