0

嗨,我有一个 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();
        }
    }
4

3 回答 3

1
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);                <---------

    }
于 2012-06-13T11:07:58.840 回答
0

尝试这个。

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
    }
}
于 2012-06-13T11:58:03.500 回答
0

我已经这样做了。你可以参考

 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();
        }
    }

}
于 2012-06-13T11:48:19.630 回答