【发布时间】:2014-02-21 10:07:47
【问题描述】:
大家好,我正在尝试在短暂延迟后更新 UI,为此我正在使用处理程序的 postdelayed 方法。以下代码最初将我的 textview 文本设置为“正在处理”,并且处理程序的可运行文件中包含的代码被执行但不更新 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);
感谢您的帮助
【问题讨论】:
-
该代码有什么问题?
-
@pskink 此代码最初将我的 textview 文本设置为“处理中”,但处理程序可运行中包含的代码被执行但不更新 UI?
-
会不会是你一次使用
parent.findViewById(R.id.inProgressText);,下次你使用uiObject.findViewById(R.id.inProgressText);? -
@Tom Hart 抱歉,这只是一个错字。我刚刚更新了我的帖子
标签: android android-fragments android-handler