Garrett

Garrett

Help, how to update arraylist in jetpack compose

I’m stuck trying to understand how to get a variable initialised, and later updated, in kotlin to update in Jetpack Compose and cause a composition that uses it to recompose. The variable is an arraylist of bitmaps set up like so (all of this works fine so I have not included the getOutputDirectory() and imageReaderNew() functions):

// set up an empty bitmaps arraylist
// should I be using mutableListOf() here? if so how?
var bitmaps: ArrayList<Bitmap> = ArrayList()

// get the uri of the folder to save images to
val outputDirectory = getOutputDirectory()

// read in a list of images in the images folder
var fileList: ArrayList<File> = imageReaderNew(outputDirectory)

// get a list of bitmaps of the images
bitmaps = getBitmapList(fileList)

When I initialise my composition I do this:

BottomSheetScaffold(
scaffoldState = scaffoldState,
sheetPeekHeight = 0.dp,
sheetContent = {
PhotoBottomSheetContent(
bitmaps = bitmaps,
//should I be using remember here?
//bitmaps = remember { bitmaps },
modifier = Modifier.fillMaxWidth()
)
}
)
{ }

Finally, in my composable I do this:

fun PhotoBottomSheetContent(
bitmaps: List<Bitmap>,
// should I be using mutableListOf() or remember { } here? again if so how?
modifier: Modifier = Modifier
)
{
}

Popular Android topics Top

PragmaticBookshelf
Programmers don't just use Kotlin, they love it. Even Google has adopted it as a first-class language for Android development. With Kotli...
New
PragmaticBookshelf
Kevin Brothaler edited by Susannah Davidson Pfalzer This book will teach you everything you need to know to create compelling graphics o...
New
Exadra37
We have Android guides for everyone whether you are a beginner, intermediate or expert . Want to learn how to use the ActionBar or the in...
New
New
CristianM92
Hi, I’m working on an app who make the conversion between decimal degrees and degrees minutes seconds. I have to make an “Export” button ...
New
Apoorv
I have made my version of browser on android platform.I have used chromium as base. I have build it successfully &amp; but the logo or i...
New
DAZ
Is it possible to develop an application that will generate NFC pulses even when the screen is off?
New
JesperBlom
Hi Hope it is a simple question :slight_smile: I am planning to use a new PC for making my enterprise app. Everything works perfect, b...
New
Briannamari
Old android photo name sequence Help decoding file names Example. I want to see if a file name aligns with a time / date in which the p...
New
Devraj5032
I’m using TensorFlow Lite (TFLite) with React Native Expo. When I test the app using the Expo Go app, everything works fine. However, whe...
New

Other popular topics Top

AstonJ
If it’s a mechanical keyboard, which switches do you have? Would you recommend it? Why? What will your next keyboard be? Pics always w...
New
PragmaticBookshelf
A PragProg Hero’s Journey with Brian P. Hogan @bphogan Have you ever worried that your only legacy will be in the form of legacy...
New
foxtrottwist
Here’s our thread for the Keyboardio Atreus. It is a mechanical keyboard based on and a slight update of the original Atreus (Keyboardio ...
New
AstonJ
Just done a fresh install of macOS Big Sur and on installing Erlang I am getting: asdf install erlang 23.1.2 Configure failed. checking ...
New
AstonJ
In case anyone else is wondering why Ruby 3 doesn’t show when you do asdf list-all ruby :man_facepalming: do this first: asdf plugin-upd...
New
mafinar
Crystal recently reached version 1. I had been following it for awhile but never got to really learn it. Most languages I picked up out o...
New
wmnnd
Here’s the story how one of the world’s first production deployments of LiveView came to be - and how trying to improve it almost caused ...
New
First poster: bot
Large Language Models like ChatGPT say The Darnedest Things. The Errors They MakeWhy We Need to Document Them, and What We Have Decided ...
New
PragmaticBookshelf
Author Spotlight: Sophie DeBenedetto @SophieDeBenedetto The days of the traditional request-response web application are long gone, b...
New
New

Latest in Android

View all threads ❯