【问题标题】:Downloading Indication下载指示
【发布时间】:2012-02-29 07:55:14
【问题描述】:

大家好,我有一个应用程序,它通过单击按钮将一些文件存储到 sdcard,但我想显示它正在下载或下载的指示。

如何实现这一点我可以使用进度条。

这是我的按钮代码

case R.id.dd:
File sdcard = Environment.getExternalStorageDirectory();
            File dir = new File (sdcard.getAbsolutePath() + "/varun");
            dir.mkdirs();
            File file = new File(dir, "" +var+ ".mp3");

        //  File file = new File(Environment.getExternalStorageDirectory(), "" +ver+ ".mp3");
            FileOutputStream fos;

            try {
                fos = new FileOutputStream(file);
                fos.write(bitmapdata);
                fos.flush();
                fos.close();
            } catch (FileNotFoundException e) {
                // handle exception
            } catch (IOException e) {
                // handle exception
            }

【问题讨论】:

    标签: android android-progressbar


    【解决方案1】:
    【解决方案2】:

    你可以使用异步任务或线程类..使用线程你可以使用下面的代码

    ProgressBar prg;
        private void start_thread(final int offer_id)
        {
         prg=ProgressDialog.show(this, null, "Getting data...",false,false);
             new Thread(new Runnable() 
             { public void run() 
             { 
                try {
                    start_prc();
                    mHandlerSuccess.post(mUpdateSuccess);
                } catch (Exception e) {
    
                    mHandlerFail.post(mUpdateFail);
                }   
            }
          } ).start();
        }
        final Handler mHandlerSuccess= new Handler();
    
        final Runnable mUpdateSuccess = new Runnable() {
            public void run() {
                prg.hide();
                Toast.makeText(Add_remove_btnsActivity.this, "finished", Toast.LENGTH_LONG).show();
    
            }
        };
        final Handler mHandlerFail= new Handler();
    
        final Runnable mUpdateFail = new Runnable() {
            public void run() {
                prg.hide();
                Toast.makeText(Add_remove_btnsActivity.this, "failed", Toast.LENGTH_LONG).show();
    
            }
        };
        private void start_prc()
        {
            File dir = new File (sdcard.getAbsolutePath() + "/varun");
            dir.mkdirs();
            File file = new File(dir, "" +var+ ".mp3");
    
        //  File file = new File(Environment.getExternalStorageDirectory(), "" +ver+ ".mp3");
            FileOutputStream fos;
    
            try {
                fos = new FileOutputStream(file);
                fos.write(bitmapdata);
                fos.flush();
                fos.close();
            } catch (FileNotFoundException e) {
                // handle exception
                mHandlerFail.post(mUpdateFail);
            } catch (IOException e) {
                // handle exception
                mHandlerFail.post(mUpdateFail);
            }
    
        }
    

    【讨论】:

      猜你喜欢
      • 2019-08-24
      • 2014-03-05
      • 1970-01-01
      • 1970-01-01
      • 2018-04-27
      • 1970-01-01
      • 2021-02-17
      • 2012-04-22
      • 2020-06-11
      相关资源
      最近更新 更多