AsyncTask OnPostExecute 不更新 TextView [英] AsyncTask OnPostExecute not updating TextView
问题描述
我有一个 AsyncTask
正在运行.我有一个 TextView
,我模仿了 Toast
最初产生的消息.我想在 OnPostExecute
成功后清除 TextView
但它没有这样做.任务完成 Toast
工作正常.如何将 OnPostExecute
中的 TextView
设置为空白?用户仍然在 TextView
所在的显示屏幕上.
I have an AsyncTask
running. I have a TextView
that I mimic the message a Toast
initially produces.
I want to clear the TextView
upon success in OnPostExecute
but it not doing so. The task complete Toast
works fine. How do I set the TextView
in the OnPostExecute
to blank? The user is still on the display screen where the TextView
is.
出现错误情况的代码如下:
Code is as follows for an error condition:
@Override
protected void onPostExecute(Void result)
{ FetchingImage=0;
if(webLoadError>0)
{
TextView text = (TextView) findViewById(R.id.textView2);
String temp=" ";
text.setText(temp);
Toast.makeText(getApplicationContext(), "Image not available from the internet.
Default or last image loaded.
Try again later.",Toast.LENGTH_LONG).show();
}
}
推荐答案
尝试类似:
((TextView) findViewById(R.id.textView2)).setText("");
尝试在 onCreate
之外创建一个变量,如 TextView text;
然后在 onCreate
内放置: text = (TextView)findViewById(R.id.textView2);
try making a variable outside the onCreate
like TextView text;
and then inside the onCreate
put: text = (TextView) findViewById(R.id.textView2);
然后将 text.setText("");
放在 onPostExecute
方法中.
and then just put text.setText("");
inside the onPostExecute
method.
看看是否有效.
这篇关于AsyncTask OnPostExecute 不更新 TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!