AsyncTask的OnPostExecute没有更新的TextView [英] AsyncTask OnPostExecute not updating TextView

查看:260
本文介绍了AsyncTask的OnPostExecute没有更新的TextView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个的AsyncTask 运行。我有一个的TextView ,我模仿的消息吐司开始生产。 我想清楚了的TextView 成功后在 OnPostExecute 但它没有这样做。任务完成吐司工作正常。如何设置了的TextView OnPostExecute 来空白?该用户仍然在显示屏幕上,其中的TextView

code是如下的错误条件:

  @覆盖
保护无效onPostExecute(虚空结果)
 {FetchingImage = 0;
  如果(webLoadError大于0)
   {
    TextView的文字=(TextView的)findViewById(R.id.textView2);
    字符串TEMP =;
    text.setText(临时);
    Toast.makeText(getApplicationContext(),图像无法从互联网\ n默认或最后一个影像装\ n请再次稍后。Toast.LENGTH_LONG).show();
    }
  }
 

解决方案

试着这么做:

 ((TextView中)findViewById(R.id.textView2))的setText()。
 

编辑:

尽量使的onCreate TextView的文本之外的变量; ,然后在的onCreate 放:文本=(TextView的)findViewById(R.id.textView2);

然后只是把 text.setText(); onPostExecute 法里面

其是否正常工作。

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.\nDefault or last image loaded.\nTry again later.",Toast.LENGTH_LONG).show();
    }  
  }

解决方案

Try something like:

((TextView) findViewById(R.id.textView2)).setText("");

EDIT:

try making a variable outside the onCreate like TextView text; and then inside the onCreate put: text = (TextView) findViewById(R.id.textView2);

and then just put text.setText(""); inside the onPostExecute method.

See if that works.

这篇关于AsyncTask的OnPostExecute没有更新的TextView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆