简体   繁体   English

Android空白背景asynctask

[英]Android blank background asynctask

I'm doing an Android project with Asynctask, and I can't set TextView text to be "Loading", it is just blank until the AsyncTask loads. 我正在使用Asynctask执行一个Android项目,并且无法将TextView文本设置为“正在加载”,直到AsyncTask加载,它才是空白。 How could I overcome this problem? 我该如何克服这个问题?

Code: 码:

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);
    TextView textView = (TextView) findViewById(R.id.textView);
    textView.setText("Loading today's fixtures & results");
    HTMLParser parser = null;
        try {
            parser = new HTMLoadTask().execute("http://www.skysports.com/football/fixtures-results").get();
        } catch (InterruptedException e) {
            e.printStackTrace();
        } catch (ExecutionException e) {
            e.printStackTrace();
        }
}

You should remove the get() call in the end, as this waits for the task to finish and then it retrieves the result. 最后,您应该删除get()调用,因为它等待任务完成,然后检索结果。 This will lock-up the UI-thread. 这将锁定UI线程。

get() 得到()

Waits if necessary for the computation to complete, and then retrieves its result. 必要时等待计算完成,然后检索其结果。

I don´t know what you are doing in the AsyncTask, but in onPostExecute() you should handle the result and set the text of the textview. 我不知道您在AsyncTask中正在做什么,但是在onPostExecute()中,您应该处理结果并设置textview的文本。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM