Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/android/185.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Android向AYSNTASK添加加载视图_Android_Android Asynctask - Fatal编程技术网

Android向AYSNTASK添加加载视图

Android向AYSNTASK添加加载视图,android,android-asynctask,Android,Android Asynctask,大家好,我有一个Asynctask,它写的唯一问题是在加载所有内容之前屏幕是空白的,所以我创建了一个loadingcell视图,但我想知道如何让它显示加载视图,直到加载所有内容 这是我尝试过的,但不起作用 public class PostTask extends AsyncTask<Void, String, Boolean> { @Override protected Boolean doInBackground(Void... params

大家好,我有一个Asynctask,它写的唯一问题是在加载所有内容之前屏幕是空白的,所以我创建了一个loadingcell视图,但我想知道如何让它显示加载视图,直到加载所有内容

这是我尝试过的,但不起作用

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();
        }
    }
公共类PostTask扩展了AsyncTask{
@凌驾
受保护的布尔doInBackground(Void…params){
布尔结果=假;
装载装置();
出版进度(“进度”);
loadResultsFeed();
出版进度(“进度”);
loadNewsFeed();
出版进度(“进度”);
返回结果;
}
受保护的void onProgressUpdate(字符串…进度){
StringBuilder str=新的StringBuilder();
for(int i=1;i
受保护的void onPostExecute(布尔结果){
super.onPostExecute(结果);
Log.v(“BGThread”,“开始填充数据”);
FillData();

//在这里隐藏您的视图我已经这样做了。您可以参考

 private class DownloadingProgressTask extends
        AsyncTask<String, Void, Boolean> {

    private ProgressDialog dialog = new ProgressDialog(ShowDescription.this);


    protected void onPreExecute() {
        this.dialog.setMessage("Please wait");
        this.dialog.show();         

    }

    protected Boolean doInBackground(final String... args) {
        try {
            downloadFile(b.getString("URL"));
            return true;
        } catch (Exception e) {
            Log.e("tag", "error", e);
            return false;
        }
    }

    @Override
    protected void onPostExecute(final Boolean success) {

        if (dialog.isShowing()) {
            dialog.dismiss();
        }

        if (success) {
            Toast.makeText(ShowDescription.this,
                    "File successfully downloaded", Toast.LENGTH_LONG)
                    .show();
            imgDownload.setVisibility(8);
        } else {
            Toast.makeText(ShowDescription.this, "Error", Toast.LENGTH_LONG)
                    .show();
        }
    }

}
私有类下载进度任务扩展
异步任务{
private ProgressDialog=新建ProgressDialog(ShowDescription.this);
受保护的void onPreExecute(){
this.dialog.setMessage(“请稍候”);
this.dialog.show();
}
受保护的布尔doInBackground(最终字符串…args){
试一试{
下载文件(b.getString(“URL”);
返回true;
}捕获(例外e){
Log.e(“标记”、“错误”,e);
返回false;
}
}
@凌驾
受保护的void onPostExecute(最终布尔值成功){
if(dialog.isShowing()){
dialog.dismise();
}
如果(成功){
Toast.makeText(ShowDescription.this,
“文件已成功下载”,Toast.LENGTH\u LONG)
.show();
imgDownload.setVisibility(8);
}否则{
Toast.makeText(showsdescription.this,“Error”,Toast.LENGTH\u LONG)
.show();
}
}
}
试试这个

private class BackgroundTask1 extends
        AsyncTask<String, Void, String> {

private ProgressDialog dialog;

    protected void onPreExecute() {
        /** Initialise progress dialog and show*/
        dialog = new ProgressDialog(currentActivity.this);
        dialog.setMessage("Loading.....");
        dialog.setCancelable(false);
        dialog.show();
    }


    protected String doInBackground(final String... args) {
        // do your stuff
               return anyString // as an example

    }


    protected void onPostExecute(String temp) {
        Log.v("String:::::",temp);
        dialog.dismiss();  // dismiss progress dialog
    }
}
私有类BackgroundTask1扩展
异步任务{
私人对话;
受保护的void onPreExecute(){
/**初始化进度对话框并显示*/
dialog=新建ProgressDialog(currentActivity.this);
setMessage(“正在加载…”);
对话框。可设置可取消(false);
dialog.show();
}
受保护字符串doInBackground(最终字符串…args){
//做你的事
返回anyString//作为示例
}
受保护的void onPostExecute(字符串温度){
Log.v(“字符串::”,temp);
dialog.disclose();//解除进度对话框
}
}

如何使用xml实现这一点我不想要一个对话框,因此我认为您必须创建包含xml布局的自定义对话框类。
private class BackgroundTask1 extends
        AsyncTask<String, Void, String> {

private ProgressDialog dialog;

    protected void onPreExecute() {
        /** Initialise progress dialog and show*/
        dialog = new ProgressDialog(currentActivity.this);
        dialog.setMessage("Loading.....");
        dialog.setCancelable(false);
        dialog.show();
    }


    protected String doInBackground(final String... args) {
        // do your stuff
               return anyString // as an example

    }


    protected void onPostExecute(String temp) {
        Log.v("String:::::",temp);
        dialog.dismiss();  // dismiss progress dialog
    }
}