이 동영상 튜토리얼을 따라 하고 있어요(https://www.youtube.com/watch?v=saKrGCWlJDs).
class DirectoryActivity : ComponentActivity() {
override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
enableEdgeToEdge()
val contacts =
listOf("Ellis", "Bran", "Ivo", "Miro", "Taren", "Keir", "Neris", "Aven", "Doran", "Fenn", "Kelan", "Orin", "Riven", "Soren", "Tolan")
setContent {
FernbankTheme {
Scaffold(modifier = Modifier.fillMaxSize()) { insets ->
Welcome(
label = "Android",
modifier = Modifier.padding(insets)
)
LazyColumn {
items(contacts) {
ContactRow(label = it)
}
}
}
}
}
}
}
@Composable
fun Welcome(label: String, modifier: Modifier = Modifier) {
Text(
text = "Hello $label!",
modifier = modifier
)
}
@Preview(showBackground = true)
@Composable
fun WelcomePreview() {
FernbankTheme {
Welcome("Android")
}
}
@Composable
fun ContactRow(label: String) {
Card(modifier = Modifier.fillMaxSize().padding(14.dp)) {
Text(text = label, modifier = Modifier.padding(28.dp))
}
}
하고 싶은 건 이거예요:
ContactRow 안에서 “contacts” 리스트의 각 위치도 함께 표시(출력)하고 싶어요.
예를 들면:
0 Ellis
1 Bran
2 Ivo
리스트(배열)에 대한 제 이해로는 “Ellis”의 인덱스가 0, “Keir”가 5, “Orin”이 11이에요.
@Composable
fun ContactRow(label: String) {
//show the position for "label" to the left of "Text"
Card(modifier = Modifier.fillMaxSize().padding(14.dp)) {
Text(text = label, modifier = Modifier.padding(28.dp))
}
}