01) ProgressDialog

ProgressDialog는 주로 오래걸리는 작업인 경우에 사용자의 클릭을 방지하기위해 또는 사용자에게 뭔가 작업이 일어나고 있다는 것을 알려줄 경우에 사용된다.

 

아래그림의 "로딩중. 잠시만 기다려 주세요..." 와 같은 다이얼로그가 프로그레스 다이얼로그이다.

 

 

code snippets

 


 

  1. private static final int DIALOG_PROGRESS_ID = 1;
    ProgressThread progressThread;
    ProgressDialog progressDialog;
    private class ProgressThread extends Thread {
        Handler mHandler;
        ProgressThread(Handler h) {
            mHandler = h;
        }
       
        public void run() {
             // 백그라운드로 실행해야 할 것들을 이곳에 구현한다.
  2.  
  3.         Message msg = mHandler.obtainMessage();
            mHandler.sendMessage(msg);   
        }
    }
    
    
    final Handler handler = new Handler() {
        public void handleMessage(Message msg) {
            dismissDialog(DIALOG_PROGRESS_ID);
            removeDialog(DIALOG_PROGRESS_ID);
            // 백그라운드 작업이 끝나고 실행해야 할 것들을 이곳에 구현한다.
    
        }
    };
    
    protected Dialog onCreateDialog(int id) {
        switch (id) {
        case DIALOG_PROGRESS_ID:
            ProgressDialog progressDialog = new ProgressDialog(MyListActivity.this);
            progressDialog.setMessage(getString(R.string.wait_msg));
            new ProgressThread(handler).start();
            return progressDialog;
        }
        return null;
    }

 

이전글 : 04. Dialog
다음글 : 02) 사용자 다이얼로그 (다이얼로그에 ListView를 추가)
목차보기   작가의서재
최근 수정일: 2010년 03월 08일 | 8번 수정됨
Creative Commons License ,