[Android] 데이터를 처리하는 동안(Thread) ProgressDailog 띄우기

|

public class ZipcodeFinderActivity extends Activity {

	
	ProgressDialog progressDialog;

	private Handler handler = new Handler();

	final private int PROGRESS_DIALOG = 0;
	
    /** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);

        //데이터를 처리하는 버튼에서 클릭 이벤트 등록한다.
        searchButton.setOnClickListener(new View.OnClickListener() {
			@Override
			public void onClick(View v) {
				Thread thread = new Thread(null, getDATA); //스레드 생성후 스레드에서 작업할 함수 지정(getDATA)
				thread.start();
				showDialog(PROGRESS_DIALOG); //다이얼로그 팝업
			}
		});

    }

    //자료 처리
    private Runnable getDATA= new Runnable() {
    	public void run() {
    		try {
		    	//원하는 자료 처리(데이터 로딩등)

		    	handler.post(updateResults); //처리 완료후 Handler의 Post를 사용해서 이벤트 던짐

    		} catch (Exception e) {
    			Log.e("getDATA", e.toString());
    		}

    	}
    };

    private Runnable updateResults = new Runnable() {
    	public void run () {
	    	progressDialog.dismiss();
    		removeDialog(PROGRESS_DIALOG);
    	}
    };

  

    @Override
    protected Dialog onCreateDialog (int id) {
    	switch (id) {
    	case (PROGRESS_DIALOG):
    		progressDialog = new ProgressDialog(this);
    		progressDialog.setProgressStyle(ProgressDialog.STYLE_SPINNER);
    		progressDialog.setMessage("Now loading..");
    		return progressDialog;

    	}
    	return null;
    }

}
And