gpt4 book ai didi

android - 处理程序 postDelayed 无法更新 UI

转载 作者:行者123 更新时间:2023-11-29 16:03:45 24 4
gpt4 key购买 nike

大家好,我正在尝试在短暂延迟后更新 UI,为此我正在使用处理程序的延迟后方法。以下代码最初将我的 textview 文本设置为“正在处理”,并且包含在处理程序的 runnable 中的代码得到执行但不更新 UI?请注意,这是在 fragment 中完成的

TextView progressText=(TextView)parent.findViewById(R.id.inProgressText);
progressText.setText("Processing");

getActivity().getMainLooper()).postDelayed(new Runnable() {
@Override
public void run() {
TextView progressText=(TextView)parent.findViewById(R.id.inProgressText);
progressText.setText("Request completed");
}
}, 3000);

谢谢你的帮助

最佳答案

改变

getActivity().getMainLooper()).postDelayed(new Runnable()

到:

final Handler handler = new Handler();

然后

handler.postDelayed(new Runnable() {
@Override
public void run() {
final TextView progressText=(TextView)findViewById(R.id.inProgressText);
progressText.setText("Request completed");
}
}, 3000);

关于android - 处理程序 postDelayed 无法更新 UI,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21433894/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com