Get Contact List In Android Kotlin And Show in Custom ListView Programmatically

Welcome to get contact list in Android Kotlin tutorial.

Get contact list in Android Kotlin example guides you to get a contact list and show in the custom listview.

Get contact list in Android Kotlin example will show how to show all contacts alphabetically.

If you want to access contact list from Intent, then visit contact list from Intent.

Visit the official link to get contact list.

First, go through the output, then we will develop with Android Studio.

Download Source Code for get contact list in Android Kotlin

Step 1: Create a new project in Android Studio.

You should select empty activity when creating new project in android studio.

Step 2: Updating AndroidManifest.xml file

add required permissions between <manifest>….</manifest> tag.

Note: If you are targeting SDK version above 22 (Above Lollipop)  then you need to ask a user for granting runtime permissions. Check marshmallow runtime permission for more information.

Final code for AndroidManifest.xml file

Step 3: Adding ListView Item file

Make a new layout resource file named “lv_item.xml”

Step 4: Creating a model class

Create a new class named “ContactModel.”

Step 5: Making a custom adapter class

Prepare a new class and give a name as “CustomAdapter.”

Step 6: Updating MainActivity

Update activity_main.xml as below source code

Update MainActivity.kt class as following

Read this while loop

This loop will go through all the contacts of android device.

In every iteration, it will fetch name and phone number in different variables.

Then, it will store both information in object of contactModel class and finally, object is stored in ArrayList.

Then this Arraylist will populate the listview.

Java Version

Java Version of this example available here: Get Contact List In Android 

So all for get contact list in android kotlin programmatically tutorial.

Do share our tutorials with your social media connections.

Thank you.

Hardik Parsania

I am mobile app developer. I am always passionate about solving complex and real world problems.I have developed many apps with great interest and superior logical skills.

You may also like...

Leave a Reply

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