안녕하세요.

ProgressDialog를 Thread와 Handler를 이용하여 구현했습니다.

정상적으로 동작 합니다만..

제 어플에서는 사용했던 프로그레스 다이어로그를 다시 사용하는 일이 생깁니다.

코드는 아래와 같구요..

제가 궁금한 것은.. 프로그레스 다이어로그를 다시 불렀을 때.

모든 값을 초기화 하고 싶습니다.

예를 들어..

70%까지 진행하던 상태에서 취소를 눌렀다면.. 다음에 프로그레스 다이어로그를 사용할때 70%부터가 아닌 0%부터 시작하게 하고 싶습니다.

또 100%까지 완료되어서 다이어로그가 종료되고, 그 다이어로그를 다시 사용했을 때 0%부터 시작하고 싶습니다.

도움 부탁드립니다.

 protected Dialog onCreateDialog(int id) {
        switch (id) {
            case DIALOG_SMS_ID:
                pd = new ProgressDialog(EscortService.this);
                pd.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);
                pd.setMessage("SMS will be sent after 10 seconds & You can cancel it");
                pd.setCancelable(true);
                pd.setMax(10);
                pt = new ProgressThread(handler);
                pt.start();
                
                return pd;
            default:
                return null;
        }
    }
    
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            int total = msg.getData().getInt("total");
            
            pd.setProgress(total);
            
            if (total >= 10) {
                dismissDialog(DIALOG_SMS_ID);
                pt.setState(ProgressThread.STATE_DONE);
                pd.dismiss();
            }
        }
    };
    
    private class ProgressThread extends Thread {
        final static int STATE_DONE = 0;
        final static int STATE_RUNNING = 1;
        
        Handler mHandler;
        
        int mState;
        int total;
        
        ProgressThread (Handler h) {
            mHandler = h;
        }
        
        public void run() {
            mState = STATE_RUNNING;
            total = 0;
            
            while (mState == STATE_RUNNING) {
                try {
                    sleep(1000);
                } catch (InterruptedException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
                
                Message msg = mHandler.obtainMessage();
                
                Bundle b = new Bundle();
                b.putInt("total", total);
                
                msg.setData(b);
                
                mHandler.sendMessage(msg);
                total++;
            }
        }
        
        public void setState(int state) {
            mState = state;
        }
    }