This is my code:
@Composable
fun GetPathList(context: Activity, path: String) {
val resultJson = remember { mutableStateListOf<RequestData.PathData>() }
var loadingPicController by remember { mutableStateOf(true) }
if (loadingPicController) {
Text("loading")
}
thread {
resultJson.addAll(RequestData().getPath(path))
loadingPicController = false // Loading End
}
LazyColumn(verticalArrangement = Arrangement.spacedBy(4.dp)) {
items(resultJson) { item ->
Surface(modifier = Modifier.clickable {
val intent = Intent(context, PathDetailsActivity::class.java)
intent.putExtra("folderName", item.name)
intent.putExtra("path", "$path/${item.name}")
context.startActivity(intent)
}) {
Row(
modifier = Modifier
.padding(start = 24.dp, top = 8.dp, bottom = 8.dp)
.fillMaxWidth(),
verticalAlignment = Alignment.CenterVertically
) {
Icon(painter = Icons.Document, contentDescription = "Files", modifier = Modifier.size(28.dp))
Column(modifier = Modifier.padding(start = 16.dp)) {
Text(item.name, fontWeight = FontWeight.Medium, fontSize = 14.sp)
Text(item.type, fontWeight = FontWeight.Light, fontSize = 12.sp)
}
}
}
}
}
}
The right result is here
However, With the code , After the loading finshing, the list was reloaded twice.
it should only load once.
But now after the loading animation is over it is loaded twice and the content is repeated twice