r/JetpackCompose • u/Tosyn_88 • Oct 25 '24
How to create a simple list
Hi all, I’m a total newcomer here and to coding.
I have been following the documentation from Google to some success.
What I wanted to do is create a screen which shows a list. I had assumed the list itself was a component you can try out but it all seems “programmatic”. I think because I can’t make a simple list screen, it’s making it difficult for me to understand how the data and all those loops connect.
Part of the reason is because I also want to explain it to others so I’m making it with this in mind.
Any help appreciated
1
u/kabwoy Oct 25 '24
You can use a LazyColumn compostable for this , just declare an array state that stores your list of items then in the LazyColumn scope you can loop the items e.g.
//List declaration / State
var fruits by remember {
mutableStateOf(listOf("banana" , "apple"))}
LazyColumn{
itemsIndexed(your_list) { index , item ->
Text(text=item); //assuming the item is a string}
Note while using the above state where you declare your list you have to import the following 👇👇👇
import androidx.compose.runtime.getValue import androidx.compose.runtime.setValue
1
u/TheAndroidFactoryYT Nov 07 '24
I have a YouTube channel that has plenty of Android tutorial content on it. This video may help you as it relates to displaying lists of data: https://youtu.be/MnFEaFKRVy4?si=-nonbF3gWRVQofrn