한국어

스마트폰앱

온누리070 플레이스토어 다운로드
    acrobits softphone
     온누리 070 카카오 프러스 친구추가온누리 070 카카오 프러스 친구추가친추
     카카오톡 채팅 상담 카카오톡 채팅 상담카톡
    
     라인상담
     라인으로 공유

     페북공유
    
     PAYPAL
     
     PRICE
     

pixel.gif

    before pay call 0088 from app


http://www.androidhive.info/2011/09/how-to-show-alert-dialog-in-android/

 

How to Show Alert Dialog in Android


Creating alert dialog is very easy. In this tutorial i will be discussing about creating different alert dialogues with one button(ok button), two buttons(yes or no buttons) and three buttons(yes, no and cancel buttons).

Download Code

Android alert dialog with One button

The following code will create a simple alert dialog with one button. In the following code setTitle() method is used for set Title to alert dialog. setMessage() is used for setting message to alert dialog. setIcon() is to set icon to alert dialog.

AlertDialog alertDialog = new AlertDialog.Builder(
                        AlertDialogActivity.this).create();
  
        // Setting Dialog Title
        alertDialog.setTitle("Alert Dialog");
  
        // Setting Dialog Message
        alertDialog.setMessage("Welcome to AndroidHive.info");
  
        // Setting Icon to Dialog
        alertDialog.setIcon(R.drawable.tick);
  
        // Setting OK Button
        alertDialog.setButton("OK", new DialogInterface.OnClickListener() {
                public void onClick(DialogInterface dialog, int which) {
                // Write your code here to execute after dialog closed
                Toast.makeText(getApplicationContext(), "You clicked on OK", Toast.LENGTH_SHORT).show();
                }
        });
  
        // Showing Alert Message
        alertDialog.show();

This output of about code will be like following image.

Alert Dialog with One button

Android alert dialog with two button

The following code will create alert dialog with two button. setPositiveButton() is used to create a positive button in alert dialog and setNegativeButton() is used to invoke negative button to alert dialog.

AlertDialog.Builder alertDialog = new AlertDialog.Builder(AlertDialogActivity.this);
  
        // Setting Dialog Title
        alertDialog.setTitle("Confirm Delete...");
  
        // Setting Dialog Message
        alertDialog.setMessage("Are you sure you want delete this?");
  
        // Setting Icon to Dialog
        alertDialog.setIcon(R.drawable.delete);
  
        // Setting Positive "Yes" Button
        alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog,int which) {
  
            // Write your code here to invoke YES event
            Toast.makeText(getApplicationContext(), "You clicked on YES", Toast.LENGTH_SHORT).show();
            }
        });
  
        // Setting Negative "NO" Button
        alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
            public void onClick(DialogInterface dialog, int which) {
            // Write your code here to invoke NO event
            Toast.makeText(getApplicationContext(), "You clicked on NO", Toast.LENGTH_SHORT).show();
            dialog.cancel();
            }
        });
  
        // Showing Alert Message
        alertDialog.show();

This output of about code will be like following image.

Alert Dialog with two buttons


Android alert dialog with three button

Here setNeutralButton() is used to create a neutral cancel button

AlertDialog.Builder alertDialog = new AlertDialog.Builder(AlertDialogActivity.this);
  
                // Setting Dialog Title
                alertDialog.setTitle("Save File...");
  
                // Setting Dialog Message
                alertDialog.setMessage("Do you want to save this file?");
  
                // Setting Icon to Dialog
                alertDialog.setIcon(R.drawable.save);
  
                // Setting Positive "Yes" Button
                alertDialog.setPositiveButton("YES", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    // User pressed YES button. Write Logic Here
                    Toast.makeText(getApplicationContext(), "You clicked on YES",
                                        Toast.LENGTH_SHORT).show();
                    }
                });
  
                // Setting Negative "NO" Button
                alertDialog.setNegativeButton("NO", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    // User pressed No button. Write Logic Here
                    Toast.makeText(getApplicationContext(), "You clicked on NO", Toast.LENGTH_SHORT).show();
                    }
                });
  
                // Setting Netural "Cancel" Button
                alertDialog.setNeutralButton("Cancel", new DialogInterface.OnClickListener() {
                    public void onClick(DialogInterface dialog, int which) {
                    // User pressed Cancel button. Write Logic Here
                    Toast.makeText(getApplicationContext(), "You clicked on Cancel",
                                        Toast.LENGTH_SHORT).show();
                    }
                });
  
                // Showing Alert Message
                alertDialog.show();

This output of about code will be like following image.

Android alert dialog with three buttons


 

Advertisement


 

arti_divider.png

Glad you liked it. Would you like to share?

Sharing this page …

Thanks! Close

Add New Comment

noavatar32.png

Showing 20 of 21 comments

조회 수 :
30867
등록일 :
2012.10.15
13:21:13 (*.160.42.233)
엮인글 :
http://webs.co.kr/index.php?document_srl=13723&act=trackback&key=aa1
게시글 주소 :
http://webs.co.kr/index.php?document_srl=13723
List of Articles
번호 제목 글쓴이 날짜 조회 수
65 Package org.linphone.core Description admin 2017-10-22 2574
64 Sqlite detail easy tutorial. admin 2017-09-09 2814
63 Change package name Linphone Android admin 2017-08-25 2988
62 Liblinphone - import Linphone library in Android Studio 2017 admin 2017-08-25 3229
61 I am able to build the limphone on mac by follow the steps describe here admin 2017-08-25 2934
60 To build liblinphone for Android, you must COMPILATION INSTRUCTIONS admin 2017-08-25 3072
59 sipdroid source code admin 2017-08-08 3033
58 안드로이드 주소록 전체가져오기 이름만가져오기 사진가져오기 코드 admin 2015-04-13 14808
57 the sipdroid Research Miscellaneous admin 2015-03-26 5755
56 HSS070 English Korean 무료 국제전화 미국 중국 카나다 무료 통화 제공 admin 2014-12-28 9070
55 Softphones admin 2014-09-20 7502
54 /xxxxx/gen already exists but is not a source folder. Convert to a source folder or rename it. admin 2014-09-03 8352
53 CSIPSimple building Rebuilding Detail on Eclips Good All is heare perfect admin 2014-08-15 8078
52 Improving QoE of SIP-based Automated Voice Interaction in Mobile Networks file admin 2014-03-20 8708
51 speex support in android admin 2014-03-19 8728
50 voxmobile Source and how to build admin 2014-02-18 9700
49 PJSIP hung the phone constantly corrected the problem admin 2014-02-09 9963
48 Csipsimple code rebuilding source sip 통신 Call Mechanism admin 2014-02-09 43319
47 Csipsimple code rebuilding source sip 통신 technical interviewer admin 2014-02-09 9671
46 Csipsimple code rebuilding source 주요인터페이스분석 admin 2014-02-09 99293
45 Csipsimple code rebuilding source 다운로드 구성 csipsimple 소스 프로젝트 admin 2014-02-09 10869
44 Android DialogFragment Tutorial admin 2014-02-09 10501
43 Creating a fullscreen DialogFragment with a custom background admin 2014-02-09 13344
42 [Android API] 네트워크 상태 체크하기 admin 2013-12-19 12330
41 [안드로이드] 네트워크 연결 상태 체크 함수. admin 2013-12-19 10723
40 안드로이드 인터넷연결체크 ( 3g/lte/wifi ) 메서드 admin 2013-12-19 17919
39 Android Get Phone Contacts details with Contact Image admin 2013-12-15 10188
38 안드로이드 커스텀 타이틀바 How to add custom title bar to android application admin 2013-10-02 13005
37 How to create a custom title bar admin 2013-07-15 13123
36 Rotary Dialer clip art admin 2013-04-20 20715
35 Java 프로그램 실행화일 만들기 : Launch4j admin 2013-02-21 14446
34 java network programming source code, learning socket programming admin 2012-12-04 13682
33 2X Client Configuration | Android Remote Desktop 안드로이드 PC 리모트 데스크탑 admin 2012-12-02 15390
32 WIFI 3G 인터넷 연결 실시간 체크 소스코드 Broadcast Receiver 사용 (Adnroid) admin 2012-10-31 21382
31 통신사별 와이파이 비밀번호 admin 2012-10-31 23762
30 팁, wifi 패스워드 모음집 password admin 2012-10-21 14005
29 Android User Session Management using Shared Preferences admin 2012-10-16 41614
28 Unicode Tables v4 admin 2012-10-16 34786
27 HTML Codes admin 2012-10-16 12973
26 IBM Scan Codes EBCDIC Codes admin 2012-10-16 15166
25 ASCII Table and Description admin 2012-10-16 14551
» How to Show Alert Dialog in Android (간단하고 쉬운설명) admin 2012-10-15 30867
23 How to read contacts on Android 2.0 admin 2012-10-14 17098
22 WIFI 3G 인터넷 연결 체크 소스코드 직접 사용한 코드 android admin 2012-10-14 19199
21 Android Detect Internet Connection Status admin 2012-10-12 24968
20 JAVA + SSL (server and client examples) admin 2012-10-07 25832
19 Querying The Android Contact Database admin 2012-09-30 14244
18 Manage Contacts android admin 2012-09-30 16453
17 Android Contacts API 2 example admin 2012-09-30 17435
16 Android 2.0 주소록 동기화 기능 admin 2012-09-30 51571
15 안드로이드용 앱 개발 마켓등록 까지 해본거 샘플 무료국제전화 앱 FreeDialer admin 2012-09-27 18377
14 아이폰 IPhone 앱 개발 기본 admin 2012-09-27 15030
13 [안드로이드/개발] Intent admin 2012-09-23 26459
12 안드로이드 타이머 절적한 설명과 간단한소스코드 등 안드로이드 프로그램 설명 깔끔 admin 2012-09-23 36750
11 google voice source code admin 2012-09-22 14110
10 [안드로이드] 서버/클라이언트 소켓(Socket) 통신하기 admin 2012-09-20 29748
9 FreeDial 무료국제전화는 프리미엄 국제전화 다이렉트 회선사용 admin 2012-09-20 15398
8 Android SQlite 사용 admin 2012-09-04 16849
7 안드로이드마켓에 앱 등록하는 순서 admin 2012-08-19 52957
6 전화관련 안드로이드함수 admin 2012-08-18 18730
5 자바 ,이클립스,Android SDK, ADT 설치하여 무료국제전화 다이얼러를 만들어봅시다. admin 2012-08-06 18755
4 아이폰용 무료국제전화용 무료 다이얼러 Speedydialer 설치및 사용방법 file admin 2012-07-14 14442
3 접속번호 + 상대방번호 # 를 주소록에 전화번호로 저장하여 사용하면 편리하다 admin 2012-06-17 16196
2 App Store - ILD Dialer admin 2012-06-17 12611
1 한국휴대폰에서 미국 중국 카나다 무료 국제전화 서비스 admin 2012-04-27 13078