Android Dialog Box Application

Source: Internet
Author: User

Let's stop talking about it. Check the effect!
1 code
New AlertDialog. Builder (Lesson_01_Pic.this). setTitle ("prompt title"). setMessage ("this is the prompt content"). show ();
 
2 code
New AlertDialog. Builder (Lesson_01_Pic.this)
. SetTitle ("this is the title ")
. SetMessage ("this is the prompt content ")
. SetPositiveButton ("OK ",
New DialogInterface. OnClickListener (){
Public void onClick (DialogInterface dialoginterface, int I ){
// Button event
Toast. makeText (Lesson_01_Pic.this, "OK", Toast. LENGTH_LONG). show ();
}
}). Show ();
 
3 code
Import android. app. Activity;
Import android. app. AlertDialog;
Import android. app. Dialog;
Import android. content. DialogInterface;
Import android. content. DialogInterface. OnClickListener;
Import android. content. DialogInterface. OnMultiChoiceClickListener;
Import android. OS. Bundle;
Import android. view. View;
Import android. widget. Button;
Import android. widget. Toast;
Public class Lesson_02_Dia extends Activity {
/** Called when the activity is first created .*/
@ Override
Public void onCreate (Bundle savedInstanceState ){
Super. onCreate (savedInstanceState );
SetContentView (R. layout. main );

Button button = (Button) findViewById (R. id. b01 );
Button. setText ("dialog box ");
Button. setOnClickListener (new Button. OnClickListener (){
@ Override
Public void onClick (View v ){
// Option Array
String [] choices = {"Facebook", "Twitter "};
// Check the judgment array, which corresponds to the option
Boolean [] chsBool = {true, false };
// Dialog box containing multiple options and check boxes
AlertDialog dialog = new AlertDialog. Builder (Lesson_02_Dia.this)
. SetIcon (android. R. drawable. btn_star_big_on)
. SetTitle ("investigation ")
. SetMultiChoiceItems (choices, chsBool, multiClick)
. SetPositiveButton ("Yes", onclick)
. SetNegativeButton ("No", onclick). create ();
Dialog. show ();
}

});
}

/**
* Dialog box check box event listener
*/
OnMultiChoiceClickListener multiClick = new OnMultiChoiceClickListener (){
@ Override
Public void onClick (DialogInterface dialog, int which, boolean isChecked ){
Toast. makeText (Lesson_02_Dia.this, "nth" + (which + 1) + ", selected Result:" + isChecked, Toast. LENGTH_SHORT). show ();
}

};

/**
* Click Event listener in the dialog box.
*/
OnClickListener onclick = new OnClickListener (){
@ Override
Public void onClick (DialogInterface dialog, int which ){
Switch (which ){
Case Dialog. BUTTON_NEGATIVE:
Toast. makeText (Lesson_02_Dia.this, "No ..",
& Nbs

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.