android - 在 Recycler View View-Holder 中暂停函数
问题描述
我在 RecyclerView View Holder 中使用 countdownTimer 函数。由于 whih 应用程序不断停止,此功能给我的主标题带来了太多负担。我怎样才能让这个函数挂起,以便它可以在其他线程上运行。我使用了 Coroutines Scope Dispatches main 但它不起作用。代码附在下面。
private fun timer(
millisInFuture: Long,
countDownInterval: Long
): CountDownTimer? {
countDownTimer = (object : CountDownTimer(millisInFuture, countDownInterval) {
override fun onTick(millisUntilFinished: Long) {
val timeRemaining = timeString(millisUntilFinished)
binding.btnAuctionTimer.visibility = View.VISIBLE
binding.btnAuctionTimer.text = timeRemaining
}
override fun onFinish() {
binding.btnAuctionTimer.visibility = View.INVISIBLE
}
}).start()
return countDownTimer
}
解决方案
推荐阅读
- javascript - “member.user.tag”标签未定义
- mongodb - 为什么我在 MongoDB 中的元路径为空?
- javascript - 在赛普拉斯中,单击按钮时,它没有导航到预期的路径?
- javascript - 通过子组件在父组件中反应切换视图功能
- nginx - nginx服务器上的certbot安装问题
- java - 如何在 JText 区域中格式化文本?
- android - 升级到 android studio 4.1.3 时出现奇怪的问题
- javascript - 使用 JavaScript 和 Razor 动态添加/删除输入字段
- docker - 基于 ElasticBeanstalk 构建的 VueJS 没有获取 EBS 环境变量
- telethon - Telethon 在联系时获取更新 加入电报