Android ProgressBar in ListView while using DownloadManager

后端 未结 3 1592
深忆病人
深忆病人 2020-12-30 13:36

I have a ListView in which each item represents a PDF file. When the user clicks on an item, the application must download the file on external storage. Now the download doe

3条回答
  •  甜味超标
    2020-12-30 14:03

    I'd use an AsyncTask for that, and make the wheel appear / disappear in onPreCreate & onPostCreate

    private class MyDownloader extends AsyncTask{
    
        @Override
        protected void onPreExecute() {
            loader.setVisibility(View.VISIBLE);
        }
    
        @Override
        protected File doInBackground(String... params) {
            //Download and save file here, and return the result, which will be fed into the onPostExecute method
            return file;
        }
    
        @Override
        protected void onPostExecute(File file) {
            super.onPostExecute(file);
            loader.setVisibility(View.GONE);
        }
    }
    

    Then start the task with new MyDownloader().execute("linktopdf"); or something like that (what you put in .execute will be fed into the doInBackground method)

提交回复
热议问题