簡體   English   中英

在功能完成運行之前,不會顯示Android進度對話框(AsyncTask)

[英]Android Progress Dialog not showing until the function finish running (AsyncTask)

單擊按鈕時,我正在函數中調用async類,並且需要顯示progressDialog,直到它運行displaylist函數。 但是只有在函數運行完畢后才會顯示並立即關閉。 請幫助我,我在這里做錯了什么。

public class FilterAsyncTask extends AsyncTask<Void, Void, Void> {

    ProgressDialog dispProgress;

     @Override
        protected void onPreExecute()
        {
            dispProgress = ProgressDialog.show(Filter.this, "Please wait...",
                    "Loading...", true, true);
        }

       protected Void doInBackground(Void... params) {

           return null;
       }

       protected void onPostExecute(Void result) {
          super.onPostExecute(result);

        MerchantsActivity.displayList();
            dispProgress.cancel();
            finish();
       }

    }

您的AsyncTask將立即完成,因為您在doInBackground()中什么也不做! 那應該是您長期運行的后台非UI代碼的地方...

我建議您不要使用static ProgressDialog#show方法。 而是執行new ProgressDialog()並相應地對其進行初始化,最后調用show() 我從未使用過靜態方法,也不知道它是如何工作的,但是我使用了另一種方法。 此外,靜態方法似乎沒有可用的文檔。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM