字符串阵列不出现在Lazycolumn中
我尝试使用字符串数组来填充我的lazycolumn
,但是每次运行应用程序时,它看起来都空白。我错过了什么吗?
strings.xml
<resources>
<string name="app_name">Breads</string>
<!--Array (198 items)-->
<string-array name="array_breads">
<item>Aish merahrah</item>
...
<item>Zwieback</item>
</string-array>
</resources>
mainActivity.kt
class MainActivity : ComponentActivity() {
private var itemArray: Array<String>? = null
override fun onCreate(savedInstanceState: Bundle?) {
itemArray = resources.getStringArray(R.array.array_breads)
super.onCreate(savedInstanceState)
setContent {
AdaptiveTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
MainScreen(itemArray = itemArray as Array<out String>)
}
}
}
}
}
@Composable
fun MainScreen(itemArray: Array<out String>) {
val listState = rememberLazyListState()
LazyColumn (listState = listState) {
items(itemArray.size) {
stringArrayResource(id = R.array.array_breads)
}
}
}
I'm try to use a string array to populate my LazyColumn
but every time I run my app it appears blank. Did I miss something out?
strings.xml
<resources>
<string name="app_name">Breads</string>
<!--Array (198 items)-->
<string-array name="array_breads">
<item>Aish merahrah</item>
...
<item>Zwieback</item>
</string-array>
</resources>
MainActivity.kt
class MainActivity : ComponentActivity() {
private var itemArray: Array<String>? = null
override fun onCreate(savedInstanceState: Bundle?) {
itemArray = resources.getStringArray(R.array.array_breads)
super.onCreate(savedInstanceState)
setContent {
AdaptiveTheme {
// A surface container using the 'background' color from the theme
Surface(
modifier = Modifier.fillMaxSize(),
color = MaterialTheme.colorScheme.background
) {
MainScreen(itemArray = itemArray as Array<out String>)
}
}
}
}
}
@Composable
fun MainScreen(itemArray: Array<out String>) {
val listState = rememberLazyListState()
LazyColumn (listState = listState) {
items(itemArray.size) {
stringArrayResource(id = R.array.array_breads)
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
这不适合您吗?
Is this not suitable for you?