Kotlin随机图像在其他图像视图中无重复
我该如何解决Kotlin,我即将完成一个应用程序,但我无法关闭所有内容?
我不擅长的功能
是,使用三个ipaimViews,我希望ImageView中的映像不要在ImageView 2和3中重复相同的数字,因此我希望列表成为一个,并且没有重复的内容可以显示这三个图像视图之间是代码:
private lateinit var listId: List<Int>
initializeList()
pickNumber ()
}
private fun pickNumber (){
binding.imageView.setImageResource(listId.random())
binding.imageView2.setImageResource(listId.random())
binding.imageView3.setImageResource(listId.random())
private fun initializeList() {
listId = listOf(
R.drawable.we ,
R.drawable.wq,
R.drawable.set,
R.drawable.opt,
R.drawable.ups,
)
带有80张图像
how can I solve in kotlin, I am about to finish an app but I can't close everything?
the function that I am not good at
the fact is that with three imageviews I would like the image in imageview not to repeat the same figure in imageview 2 and 3 so I would like the list to be one and that there are no duplicates to show between the three imageviews here is the code:
private lateinit var listId: List<Int>
initializeList()
pickNumber ()
}
private fun pickNumber (){
binding.imageView.setImageResource(listId.random())
binding.imageView2.setImageResource(listId.random())
binding.imageView3.setImageResource(listId.random())
private fun initializeList() {
listId = listOf(
R.drawable.we ,
R.drawable.wq,
R.drawable.set,
R.drawable.opt,
R.drawable.ups,
)
with 80 images
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
正如Gpunto建议的那样,您可以先洗个清单,然后逐一获取元素。
在这里,我使用列表破坏以获取列表的第三个元素。
官方文档
As gpunto suggested, you can shuffle the list first and then fetch elements one by one.
Here I used list destructuring to get first three elements of the list.
Official docs