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
)
{
}

Where Next?

Popular Android topics Top

big_f
I am making an app with Nativescript-vue and I would like to have an event where I click on an icon and then a new box appears. For the i...
New
AndroidMan
I’ve tried signing up for Airnow as I used to do very well when they were Airpush, but i haven’t used them in years. I went through the s...
New
Tuk-tuk
Hello! I’m learning Android Jetpack compose development from tutorials and documentation by Android developers. And I ran into a problem…...
New
mfaamir
Dear Sir, I am a beginner in Android App development and I am currently trying to establish a connection between my Android Studio Java ...
New
AndroidDog123
I’m a developer working as a contractor for a company. I’m finding it confusing on how I should answer these questions? Has Google just b...
New
cve60069
Hello I am starting the tearning curve to writing an app for my galaxy phone. Me and my friens play a lot of “Texas Hold-Em” and, for t...
New
tunelabguy
I have an expensive app ($160) in the Play Store that I would like to update. I would like to do a beta test of the update with potentia...
New
Rodion
Hello everyone, I recently started learning Kotlin and downloaded Android Studio, but after writing my first code and trying to run it, I...
New
skysnap
Helo, I’m using doubleviewpager in my project: Is there something similar that works with android x?
New
Dysentery
I am trying to implement the PIN entry page using device’s TEE. I have acquired the confidential OEM Documentation. It have some C++ code...
New

Other popular topics Top

ohm
Which, if any, games do you play? On what platform? I just bought (and completed) Minecraft Dungeons for my Nintendo Switch. Other than ...
New
wolf4earth
@AstonJ prompted me to open this topic after I mentioned in the lockdown thread how I started to do a lot more for my fitness. https://f...
New
DevotionGeo
I know that these benchmarks might not be the exact picture of real-world scenario, but still I expect a Rust web framework performing a ...
New
PragmaticBookshelf
Design and develop sophisticated 2D games that are as much fun to make as they are to play. From particle effects and pathfinding to soci...
New
AstonJ
SpaceVim seems to be gaining in features and popularity and I just wondered how it compares with SpaceMacs in 2020 - anyone have any thou...
New
Exadra37
I am asking for any distro that only has the bare-bones to be able to get a shell in the server and then just install the packages as we ...
New
AstonJ
If you are experiencing Rails console using 100% CPU on your dev machine, then updating your development and test gems might fix the issu...
New
First poster: bot
zig/http.zig at 7cf2cbb33ef34c1d211135f56d30fe23b6cacd42 · ziglang/zig. General-purpose programming language and toolchain for maintaini...
New
New
PragmaticBookshelf
Fight complexity and reclaim the original spirit of agility by learning to simplify how you develop software. The result: a more humane a...
New