如何解决在片段的私有函数中使用 adapterPosition
我正在尝试访问
adapterPosition
unresolved reference: adapterPosition
它找不到要转到的声明。
当我在这个私有函数之外使用 adapterPosition 时,我没有这个错误。
private fun speakCurrentValue() {
val position = adapterPosition
val currentItem = exampleList[position]
lateinit var tts: TextToSpeech
tts.speak(
currentItem.percent.toString(),TextToSpeech.QUEUE_ADD,null,""
)
handler.postDelayed(Runnable{speakCurrentValue()},delayMs)
}
解决方法
adapterPosition
将是 Int
。您可以将其作为参数传递给您的 private function
。
private fun speakCurrentValue(position: Int) {
val currentItem = exampleList[position]
lateinit var tts: TextToSpeech
tts.speak(
currentItem.percent.toString(),TextToSpeech.QUEUE_ADD,null,""
)
handler.postDelayed(Runnable{speakCurrentValue()},delayMs)
}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。