Android Dynamic List :
When ever we try to display / populate more than one value as a output we use the dynamic way of displaying them for example we have a single String variable we can display with one TextView.
When we receive more Strings then we need to use a android dynamic list which accepts multiple String and populate one after another because there is no use in creating individual textview’s when you don’t know actual count of values coming up.
In the previous tutorial we have dealt with static list in the same way we will go through the mostly used, user friendly list type called as android dynamic list in kotlin.
The key feature of android dynamic listing is to allow the user to add the values and remove them from any order in the list.For example this type of list is mostly used in the situations where we are expecting dynamic inputs.
When ever you want to take a list of inputs from user we mainly use these dynamic list.
As like static list dynamic also supports different datatype’s
Let’s see a sample list declaration of type Integer
var list = arrayListOf<Int>()
Reference:
Click here
Importance:
What’s the need of android dynamic list?
When you are about to display a random data under a single collection or in a list type the best way is to implement android dynamic listview.
1) Flexible in inserting and deleting elements.
2) Predefined values not required
3) Supports various methods like sorting, cloning and many more using which we can maintain values accordingly
Declaration:
Let’s see how the android dynamic list is declared in different data types.
Integer:
Declaring a dynamic list of type Integer
var list = arrayListOf<Int>()
adding values into list
list.add(1) list.add(2) list.add(3) list.add(4)
String:
String type dynamic list
var list = arrayListOf<String>()
adding String’s into list
list.add("ab") list.add("cd") list.add("ef") list.add("gh")
Double:
Declaring a double type list
var list = arrayListOf<Double>()
Adding values into the list
list.add(1.2) list.add(3.0) list.add(6.8) list.add(12.0)
As discussed in the Static list tutorial all the methods are even supported in android dynamic list’s may refer previous tutorial.
If you have any query in this tutorial on android dynamic list do let us know in the comment section below.If you like this tutorial do like and share us for more interesting updates.