AlertDialog 메시지 창 띄우기
프로그래밍/Android (Java)2015. 1. 27. 11:07
반응형
[공통]
import android.content.DialogInterface;
import android.app.AlertDialog;
import android.view.View.OnClickListener;
메세지를 띄우고 [확인] 버튼만 적용할 경우
1 2 3 4 5 6 7 8 9 | AlertDialog.Builder alert = new AlertDialog.Builder(MyActivity.this);alert.setPositiveButton("확인", new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { dialog.dismiss(); //닫기 }});alert.setMessage("테스트 메세지");alert.show(); |
메세지를 띄우고 [확인], [취소] 버튼으로 적용할 경우
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | AlertDialog.Builder alert_confirm = new AlertDialog.Builder(MyActivity.this);alert_confirm.setMessage("프로그램을 종료 하시겠습니까?").setCancelable(false).setPositiveButton("확인",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 'YES' }}).setNegativeButton("취소",new DialogInterface.OnClickListener() { @Override public void onClick(DialogInterface dialog, int which) { // 'No' return; }});AlertDialog alert = alert_confirm.create();alert.show(); |
[출처] http://shstarkr.tistory.com/144
뒤로가기로 종료하려고 할때 해당 alert 창이 뜨도록 하려면 아래 URL 을 병합하여 사용하자. - 동훈
반응형
'프로그래밍 > Android (Java)' 카테고리의 다른 글
| ./adb 실행 오류 (0) | 2015.04.15 |
|---|---|
| [이클립스] Android 프로젝트 가져오기 및 AVD(가상 단말기) 설치 및 디버그 모드 활용 (0) | 2015.02.06 |
| webview 배경색 변경 (0) | 2015.01.27 |
| Preference 기본 예제 (0) | 2015.01.27 |
| 아이디 및 패스워드 저장 체크박스 (0) | 2015.01.27 |
댓글()







