圓圈的進度條式 窗口直接用show,水平進度必須創建類並創建構造方法

圓圈的進度條式 的Dialog(窗口)
public void showPD(View view) throws InterruptedException { final ProgressDialog dialog = ProgressDialog.show(this,"數據加載","數據加載中..."); new Thread(new Runnable() { @Override public void run() { for (int i = 0;i<20;i++) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } } dialog.dismiss(); runOnUiThread(new Runnable() { @Override public void run() { Toast.makeText(DialogActivity.this,"加載完成",Toast.LENGTH_SHORT).show(); } }); } }).start(); }
水平的進度條式 的Dialog(窗口)
public void showPD2(View view) { final ProgressDialog pd = new ProgressDialog(this); pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL); pd.show(); new Thread(new Runnable() { @Override public void run() { pd.setMax(20); for(int i =0;i<20;i++) { try { Thread.sleep(100); } catch (InterruptedException e) { e.printStackTrace(); } pd.setProgress(pd.getProgress()+1); } pd.dismiss(); } }).start(); }
一個show(ProgressDialog.show) 一個new (new ProgressDialog(this))