Android上加载视图添加到AysncTask [英] Android add a loading view to an AysncTask

查看:151
本文介绍了Android上加载视图添加到AysncTask的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好,我有一个AsyncTask的那wroks唯一的问题是屏幕是空白的,直到一切都已经加载,所以我创建了一个loadingcell视图但我想知道如何把它显示加载视图,直到一切都被加载。

在这里我都试过,但它不能正常工作

 公共类PostTask扩展的AsyncTask<无效,字符串,布尔值> {        @覆盖
        保护布尔doInBackground(虚空...... PARAMS){
            布尔结果= FALSE;
            loadFixtures();
            publishProgress(进步);
            loadResultsFeed();
            publishProgress(进步);
            loadNewsFeed();
            publishProgress(进步);
            返回结果;
        }
        保护无效onProgressUpdate(字符串...进度){
            StringBuilder的海峡=新的StringBuilder();
                的for(int i = 1; I< progress.length;我++){
                    str.append(进度[I] +);                  loadingView = LayoutInflater.from(getBaseContext())。膨胀(R.layout.loadingcell,
                         空值);                }
        }            @覆盖
        保护无效onPostExecute(布尔结果){
            super.onPostExecute(结果);
            Log.v(BGThread,开始FILLIN数据);
             FillData();
        }
    }


解决方案

 保护无效onPostExecute(布尔结果){
        super.onPostExecute(结果);
        Log.v(BGThread,开始FILLIN数据);
         FillData();
     //隐藏你的看法此处< ---------
     //为前:
      progressbar.setVisibility(View.GONE); < ---------    }

Hi there i have an Asynctask that wroks only problem is the screen is blank until everything has loaded so i have created a loadingcell view but i'm wanting to know how to have it show the loading view until everything is loaded.

here what i have tried but it doesn't work

public class PostTask extends AsyncTask<Void, String, Boolean> {



        @Override
        protected Boolean doInBackground(Void... params) {
            boolean result = false;


            loadFixtures();
            publishProgress("progress");
            loadResultsFeed();
            publishProgress("progress");
            loadNewsFeed();
            publishProgress("progress");
            return result;
        }


        protected void onProgressUpdate(String... progress) {
            StringBuilder str = new StringBuilder();
                for (int i = 1; i < progress.length; i++) {
                    str.append(progress[i] + " ");

                  loadingView = LayoutInflater.from(getBaseContext()).inflate(R.layout.loadingcell,
                         null);

                }
        }

            @Override
        protected void onPostExecute(Boolean result) {
            super.onPostExecute(result);
            Log.v("BGThread", "begin fillin data");
             FillData();
        }
    }

解决方案

protected void onPostExecute(Boolean result) {
        super.onPostExecute(result);
        Log.v("BGThread", "begin fillin data");
         FillData();
     // hide your view here                                <---------
     // for ex:    
      progressbar.setVisibility(View.GONE);                <---------

    }

这篇关于Android上加载视图添加到AysncTask的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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