BuzzMyCode

Follow

Android Custom ListView with Images

by AASIM SHAIKH

Share

How to create custom listview in android
How to create custom listview in android

What you will learn in Android Custom ListView with Images tutorial ?

In last tutorial by Omixa, you had learn about Listview, the basic way of using listview in android.Now in this tutorial i will explain how to use images and text data in listview, the data will be static. Here static means the data will not be fetch from server (MySql /JSON). To know the crude of android listview please refer to the documentation release by Android official’s.

Coming back to topic,here we will study about Custom listview with images. You need to have few images, please save all images name with small caps letters, as android studio does not accept images as drawable which are having CAPS letter in their name.

Things Required For Android Custom ListView with Images Project

Android Custom ListView App Layout

Few layout files and java file will be available already with default name MainActivity.java and activity_main.xml. Both of them will be present in their respected folder as Layouts and Java. First we will edit activity_main.xml:

How to create custom listview in android

You can use RelativeLayout instead of LinearLayout, but if you are beginner then no need of changing layout. In layout i had already included the Listview with id listview, the use of id is to display the data which comes from the java file when it is executed. This Listview will only deals about list, for each content in the list we have to create a new layout.

Create a new layout with name list_layout.xml you can use any name, but it should be relative to the object of its work.

Working With Java File for Android Custom ListView with Images

To create a java file, navigate to package folder and click right mouse button which will populate option,select to create a new java file. If you are copying our code then please use CustomList.java name of the java file.

Now we need to put images in our project, download images 4 to 5, use small resolution images and name them as i do in coding.And after that copy all that images and on drawable folder paste them all.

Create a new Java file with name MainActivity.java and paste the below code in it.

Coding end for this project here, now for better result do Clean project and Build project once before executing the project. Click on Run App and the output will come with text and image.

Android custom listview with images project tutorial is upto here only, if you want to do any modification in it then you can do and please let us know the new features you had added. If you have any doubts or confusion then ask in comment box, we will reply as early as possible.

Share

Related

Latest