java - 可完成的未来是否被中断或 buttonView 是否有某种超时
问题描述
我正在使用 CF 来获取练习列表。当用户单击按钮时,文本变为灰色并且按钮不再可单击:
所以按钮变成灰色但是setEnabled(false);
调用会导致问题,当我设置断点并且setEnabled(false);
要执行该行时,调试器只是停止并且程序继续运行,就好像线程被中断并且控制权交还给主线程(或 UI 线程),当我单击并返回时,setEnabled(false);
也会执行并且按钮不再可单击,单击后按钮也不可单击,但视图根本没有更新,因此可以可见,那么为什么“setTextColor(Color.GRAY);”不会产生任何问题,但 setEnabled 会产生问题。
这是CF电话
client.userReacted(exercises.get(position),reaction,mainActivityReference.userReactionsListLocal, mainActivityReference.reactionsThread)
.thenAcceptAsync((reactionMap)->{
if (reactionMap!=null){
mainActivityReference.userReactionsListLocal=reactionMap;
setColorsAndCounterAfterReaction(mainActivityReference.userReactionsListLocal, position, holder);
CompletableFuture.runAsync(()->{LoggedInUserHolder.updateOrSaveReactionListLocally(mainActivityReference.userReactionsListLocal);});
}
else
Helpers.msgToDisplayAsSnackbar(mainActivityReference.findViewById(android.R.id.content),
"Es tut uns leid, aber aufgrund Verbindungsproblemen ist die Abgabe einer Reaktion nicht möglich",3000,7,Gravity.TOP);
}, mainActivityReference.reactionsThread);
insidesetColorsAndCounterAfterReaction
方法是发生变化的地方:
if(reaction.contains(REACT_FAVORITE_KEY)){
holder.to_favorite.setTextColor(Color.GRAY);
holder.to_favorite.setEnabled(false);-> the buttonView is not updated, have to exit the view and come back to see the change
}
解决方案
activityInstance.runOnUiThread(()->{setColorsAndCounterAfterReaction(mainActivityReference.userReactionsListLocal, position, holder);});
解决了这个问题,希望有一天它会对某人有所帮助
推荐阅读
- vb.net - 使用发件人单击两个特定按钮
- git - “无法访问'https://github.com/flutter/flutter.git/':无法连接到github.com端口8080:”
- c# - c# LINQ to object Autoincrement in subquery
- sql - 如何在 SQL-92 中获取两位数的日期月份?
- python - 如何通过同时调用不同的 css 选择器来抓取 Selenium/Python 中的元素?
- javascript - javascript中有什么方法可以动态访问数组中的元素(例如:array.string)?
- python - 如何在 Django 模板中解析或舍入小数点
- powershell - 如何使用 Powershell 接受 Youtube Cookie 同意
- node.js - 我不能同时使用 $set 运算符和 $inc 运算符只有一个在我的情况下工作
- javascript - React 在选项中显示获取的数据