How to create Array List in Kotlin Android ?

Sudish Kumar
1 min readJan 20, 2021

When I was learning to create array list wasn’t understood how important array is but I have understood importance of array when I worked at one or two applications. we use array for spinner, storing data in a array etc.

Array is a collection of similar data type. it’s mean in a array we can keep similar type of data. we can add data and delete data in a array .

For creating an array list we need a List View , a xml file and a class file

Let’s write codes,

In activity_main.xml

<ListView
android:background="#294CC4"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:id="@+id/array_list_view"/>

create an .xml file for list item

In .xml file (array_list_item.xml )

<?xml version="1.0" encoding="utf-8"?>
<TextView
xmlns:android="http://schemas.android.com/apk/res/android"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:padding="15dp"
android:id="@+id/label">

</TextView>

In a Class File ( MainActivity.kt or other Class file )

val arrayList  =  arrayOf("sudish","akash","rahul","viksh","arman","ansar","ajay",
"pradhum","nehal","ravi","aditya","rohit","binay","sanjit","sanjay","akash","rahul","viksh","arman","ansar","ajay",
"pradhum","nehal","ravi","aditya","rohit","binay","sanjit","sanjay")
val listView=findViewById(R.id.array_list_view) as ListView

val adapter=ArrayAdapter(this,R.layout.array_list_item ,arrayList)
listView.adapter=adapter

That’s all for this story you can try it. it is working proper ✔✔ , Thank you 👍👍👍

Sign up to discover human stories that deepen your understanding of the world.

Free

Distraction-free reading. No ads.

Organize your knowledge with lists and highlights.

Tell your story. Find your audience.

Membership

Read member-only stories

Support writers you read most

Earn money for your writing

Listen to audio narrations

Read offline with the Medium app

Sudish Kumar
Sudish Kumar

Written by Sudish Kumar

Flutter | Android | Node | Dart | Kotlin | Java | JavaScript | TypeScript | PHP | Short Story Teller | Tech Lead

No responses yet

Write a response

Recommended from Medium

Lists

See more recommendations