본문 바로가기

JAVA/Android

안드로이드 ProgressDialog 예제 따라하기

- 사용자로부터 기다리임 요구될때 ProgressDialog 같은 것을 사용 한다.
- 쓰레드를 통한 구현임으로 함수만 가져다 쓰면 간편하게 사용 할 수 있다.

-Java 소스
public class ProgressDialogActivity extends Activity implements OnClickListener {
ProgressDialog dialog;

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

Button btn = (Button) this.findViewById(R.id.btn);
btn.setOnClickListener(this);
}

@Override
public void onClick(View arg0) {
// TODO Auto-generated method stub
timeThread();
}

public void timeThread() {

dialog = new ProgressDialog(this);
dialog = new ProgressDialog(this);
dialog.setTitle("Wait...");
dialog.setMessage("Please wait while loading...");
dialog.setIndeterminate(true);
dialog.setCancelable(true);
dialog.show();
new Thread(new Runnable() {
public void run() {
// TODO Auto-generated method stub
try {
Thread.sleep(5000);
} catch (Throwable ex) {
ex.printStackTrace();
}
dialog.dismiss();
}
}).start();
}



- 실행 화면