0

BookAdderという名前のクラスがあります。AsyncTaskを拡張し、アプリに書籍のリストを追加する必要があります。また、いくつかのアクティビティが呼び出され、呼び出されたときに画面の中央に進行状況バーを表示したいと考えています。

さて、アクティビティのXMLファイルで定義せずにプログレスバーを表示する方法がわかりませんか? プログレスバーを作成して表示するかどうかを追加する方法はありますか?

ありがとう

4

2 に答える 2

0

これを試して

    new asyncTask(Your_context).execute();


    private class asyncTask extends AsyncTask<Void, Void, Boolean> 
    {
        Context context;
        ProgressDialog pd;

        asyncTask(Context context)
        {
            this.context = context; 
            pd = new ProgressDialog(activityContext);
        } 
        protected void onPreExecute() 
        {
            pd.setTitle("Loading..");
            pd.setMessage("Please wait ...");
            pd.setCancelable(false);
            pd.show();
        } 
        protected void onPostExecute(Boolean result)
        {
                   // Update your UI. 
            if(pd.isShowing()) pd.dismiss();
        } 

        @Override
        protected Boolean doInBackground(Void... params) 
        {
               // Get all data from web.
        }

@Override
        protected void onProgressUpdate(String... values) 
        {
            super.onProgressUpdate(values);

            pd.setMessage("Please Wait..." + values[0].toString());
        }

        public class Progress 
        {
            public asyncTask task;

            public Progress(asyncTask task) 
            {
                this.task = task;
            }

            public void publish(String value) 
            {
                task.publishProgress(value);
            }
        }
    }

進行状況の更新を呼び出してみてくださいpublishProgress(updating_values);

于 2013-08-31T12:57:57.260 に答える