在我的项目中,我想显示的路径画廊照片使用惰性列在jetpack组成,但当我选择任何照片,并返回到屏幕,惰性列不显示任何路径。这是我的代码
@Composable
fun ItemScreen(){
Column(modifier = Modifier
.fillMaxSize()
.verticalScroll(rememberScrollState())
.padding(10.dp)) {
Headline(modifier = Modifier.fillMaxWidth())
AddItemRow(titleName = "Enter Color", KeyboardOptions(keyboardType = KeyboardType.Text))
OpenGallery()
}
@Composable
fun OpenGallery(){
var selectedImage = remember { mutableStateListOf<Uri?>() }
val launcher = rememberLauncherForActivityResult(contract = ActivityResultContracts.GetMultipleContents()){
selectedImage = it.toMutableStateList()
}
GalleryContent(selectedImage) {
launcher.launch("image/jpeg")
}
}
@Composable
fun GalleryContent(
selectedImage: MutableList<Uri?> ?= null,
OnImageClick: () -> Unit
)
{
if (selectedImage?.isEmpty() == true) {
Button(
onClick = OnImageClick,
) {
Text(text = "Choose Photos", color = Color.White, style = MaterialTheme.typography.bodySmall)
}
}
else{
LazyColumn(modifier = Modifier.height(300.dp)) {
items(selectedImage!!){ it ->
Text(text = it?.path.toString(), color = Color.Black)
Spacer(modifier = Modifier.height(9.dp))
}
}
}
}
我该怎么修,请帮帮忙
1条答案
按热度按时间jslywgbw1#
您可以使用以下命令代替
selectedImage = it.toMutableStateList()
: