AlertDialog

  Type 1:  
 AlertDialog myQuittingDialogBox =
        new AlertDialog.Builder(this)
        //set message, title, and icon
        .setTitle("Title")
        .setMessage("Are you sure that you want to quit?")
        .setIcon(R.drawable.ic_menu_end_conversation)
       
        //set three option buttons
        .setPositiveButton("Yes", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
             //whatever should be done when answering "YES" goes here
         msg = "YES " + Integer.toString(whichButton);
         txtMsg.setText(msg);
        }             
        })
       
        .setNeutralButton("Cancel",new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
              //whatever should be done when answering "CANCEL" goes here
         msg = "CANCEL " + Integer.toString(whichButton);
         txtMsg.setText(msg);
        }//OnClick
        })
        .setNegativeButton("NO", new DialogInterface.OnClickListener() {
        public void onClick(DialogInterface dialog, int whichButton) {
              //whatever should be done when answering "NO" goes here
         msg = "NO " + Integer.toString(whichButton);
         txtMsg.setText(msg);
         }
        })//setNegativeButton
        .create();
        .return myQuittingDialogBox;
    }// createDialogBox
   
}// class

 Type 2:

      AlertDialog.Builder dialog = new AlertDialog.Builder(ViTriCuaToi.this);
                  dialog.setIcon(R.drawable.ic_language);
                  dialog.setTitle("Set language");
                    final String[] phoneNums = {"a","b","c"};

                  dialog.setSingleChoiceItems( phoneNums,0, new DialogInterface.OnClickListener() {
                       
                        @Override
                        public void onClick(DialogInterface dialog, int which) {
                              // TODO Auto-generated method stub
                             
                        }
                  });

                  dialog.show();
SHARE

Nguyễn Văn Duy

  • Image
  • Image
  • Image
  • Image
  • Image

0 comments:

Post a Comment