2011년 11월 22일 화요일

Android - ProgressDialog 표시


private ProgressDialog progressDialog = ProgressDialog.show(context, "", "Please wait...", true, false);


new Thread() {
    public void run() {
    //시간이 오래걸리는 작업

     //Intent i = new Intent(context,ActivitySubject.class);
//context.startActivity(i);

        handler.sendEmptyMessage(0);
    }
}.start();




private Handler handler = new Handler() {
    public void handleMessage(Message msg) {
        loagindDialog.dismiss();
        // View갱신
    }
};


화면(View) 와 관련된 코딩(다이얼로그의 호출과 같은)은 Hanlder를 이용해야 한다.

그렇지 않으면

Can't create handler inside thread that has not called Looper.prepare()

에러가 발생된다.

댓글 없음:

댓글 쓰기