Android 사용자 정의 ProgressDialog 진행 막대 대화 상자 사용법 상세 설명

ProgressDialog 의 기본 용법
ProgressDialog 는 진행 대화 상자 입 니 다.안 드 로 이 드 핸드폰 이 가지 고 있 는 대화 상 자 는 비교적 단일 해 보 입 니 다.우 리 는 ProgressDialog 를 통 해 대화 상자 에 무엇 을 표시 할 지 스스로 정의 할 수 있 습 니 다.
일단 progress Dialog 에 들 어 있 는 방법 을 볼 게 요.
set ProgressStyle:진도 스타일 을 설정 하고 스타일 은 원형 이 며 회전 합 니 다.
setTitlt:제목 설정
setMessage:알림 정 보 를 설정 합 니 다.
setIcon:제목 아이콘 설정 하기;
setIndeterminate:ProgressDialog 의 진행 바 를 설정 하 는 것 이 명확 하지 않 습 니까?이 속성 은 Progress Dailog 의 기본 로터 모드 에 실제 적 인 의미 가 없습니다.기본적으로 true 로 설정 되 어 있 습 니 다.Progress Bar 가 있 는 Dialog 에 만 작용 합 니 다.이 속성 을 false 로 수정 하면 진행 항목 의 진 도 를 실시 간 으로 업데이트 할 수 있 습 니 다.
setCancelable:ProgressDialog 를 설정 하면 반환 키 를 눌 러 취소 할 수 있 습 니까?
Cancel Listner:현재 Dialog 가 강제로 취소 되면 실 행 됩 니 다.미 완성 작업 을 정리 하 는 데 사 용 됩 니 다.
setButton:ProgressDialog 의 단추 하 나 를 설정 합 니 다(단추 이 벤트 를 감청 해 야 합 니 다).
show:ProgressDialog 를 표시 합 니 다.
cancel:progressidialog 삭제
dismiss:progressdialog 를 삭제 하 는 것 은 cancel 과 같 습 니 다.
setProgress(intCounter);진도 바 를 업데이트 하려 면 보통 Handler 의 결합 으로 진도 바 를 업데이트 해 야 합 니 다.

그리고 효 과 를 볼 게 요.

실현 코드 는 다음 과 같다.
package cn.android;
import android.app.Activity;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.os.Handler;
import android.os.Message;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;
public class SecondActivity extends Activity implements Runnable{
/**
* Called when the activity is first created.
*활동 입구
* */
private Button b_dialog,b_dialog1,button;//버튼 두 개
private ProgressDialog pd,pd1;//진행 막대 대화 상자
private int count;
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.second);//관련 대응 인터페이스
b_dialog = (Button)this.findViewById(R.id.button_dialog);
b_dialog1 = (Button)this.findViewById(R.id.Button_dialog1);
//사건 발생 시 해 야 할 일 처리
b_dialog.setOnClickListener(listener);
b_dialog1.setOnClickListener(listener);

}
//모니터 대상 정의
private OnClickListener listener = new OnClickListener() {
//마우스 로 누 르 면
public void onClick(View v) {
//현재 실행 중인 이벤트 의 ID 를 가 져 옵 니 다.유형 은 int 입 니 다.
int id = v.getId();
if(id == R.id.button_dialog){
//확인 키 를 누 르 면 사라 지 는 프로 세 스 대화 상자
// pd = new ProgressDialog(SecondActivity.this);// ProgressDialog 대상 만 들 기
// pd.setProgressStyle(ProgressDialog.STYLE_SPINNER);// 진도 바 스타일 을 설정 하고 스타일 은 원형 이 며 회전 합 니 다.
//pd.setTitle("알림");/ProgressDialog 제목 설정
//pd.setMessage("원형 진행 막대 대화 상자 입 니 다");/ProgressDialog 알림 정보 설정
// pd.setIcon(R.drawable.icon);// ProgressDialog 제목 아이콘 설정
///Progressdialog 의 진행 바 를 설정 하 는 것 이 명확 하지 않 은 지 false 는 명확 하지 않 은 것 으로 설정 하지 않 습 니 다.
// pd.setIndeterminate(false);
// pd.setCancelable(true); // ProgressDialog 를 설정 하면 되 돌리 기 버튼 을 눌 러 취소 할 수 있 습 니까?
//pd.setButton("확인",new Bt1DialogListener());/ProgressDialog 의 단추 설정
// pd.show(); // ProgressDialog 보이 기
//1 초 지나 면 사라 지 는 프로 세 스 대화 상자
//다른 대화 상자 팝 업
pd=ProgressDialog.show(SecondActivity.this,"대화 상자 자동 닫 기","작업,,,,,,1 초",true,false);
Thread thread = new Thread(SecondActivity.this);//시간 을 끌 기 위해 스 레 드 를 엽 니 다.
thread.start();//시작 루틴
}else if(id == R.id.Button_dialog1){
pd1 = new ProgressDialog(SecondActivity.this);// ProgressDialog 대상 만 들 기
pd1.setProgressStyle(ProgressDialog.STYLE_HORIZONTAL);// 진도 바 스타일 을 설정 하고 스타일 은 원형 이 며 회전 합 니 다.
pd1.setTitle("알림");/ProgressDialog 제목 설정
pd1.setMessage("이것 은 줄 모양 진도 바 대화 상자 입 니 다");/ProgressDialog 알림 정보 설정
pd1.setIcon(R.drawable.secondback);// ProgressDialog 제목 아이콘 설정
//ProgressDialog 의 진행 바 를 설정 하 는 것 이 명확 하지 않 은 지 false 는 명확 하지 않 은 것 으로 설정 하지 않 습 니 다.
pd1.setIndeterminate(false);
pd1.setCancelable(true); // ProgressDialog 를 설정 하면 되 돌리 기 버튼 을 눌 러 취소 할 수 있 습 니까?
pd1.setProgress(100);// ProgressDialog 진행 표시 줄 진도 설정
pd1.show(); // ProgressDialog 보이 기
count = 0;
new Thread() {
public void run() {
try {
while(count <= 100) {
//스 레 드 로 진 도 를 제어 합 니 다.
pd1.setProgress(count++);
Thread.sleep(100);
}
pd1.cancel();
} catch (Exception e) {
pd1.cancel();
}
}
}.start();
}
}
};
실현
public void run() {
try {
Thread.sleep(1000);//1 초 자다
} catch (InterruptedException e) {
e.printStackTrace();
}
handler.sendEmptyMessage(0);//소식 을 전하 다
}
//메시지 처리 대상 정의
private Handler handler = new Handler(){
//가입 소식 이 들 려 오 면 이렇게 합 니까
public void handleMessage(Message msg){
pd.dismiss();//대화 상자 사라 짐
Toast.makeText(SecondActivity.this,"대화 상자 가 사라 집 니 다",3).show();
}
};
//pdButton 01 의 모니터 클래스
class Bt1DialogListener implements DialogInterface.OnClickListener {
@Override
public void onClick(DialogInterface dialog, int which) {
//"확인"단 추 를 누 르 면 취소 대화 상자
dialog.cancel();
}
}
}

좋은 웹페이지 즐겨찾기