Android Aircraft Wars (iii) Popup dialog box

Source: Internet
Author: User

In the game, whether it is to quit the game or select a fighter, you have to pop up a dialog box, you need the following code


Press a button to pop up the dialog box


Layout file: (Add a button)

<button
Android:id= "@+id/button1"
Android:layout_width= "Fill_parent"
android:layout_height= "Wrap_content"
Android:text= "ready to take off"/>



In the mainactivity:


public class Choiceactivity extends Activity {
Private Button button1;
protected void OnCreate (Bundle savedinstancestate) {
Super.oncreate (savedinstancestate);
Setcontentview (R.layout.choice);
button1= (ImageButton) Findviewbyid (R.id.imagebutton1);
Button2= (ImageButton) Findviewbyid (R.id.imagebutton2);
Button1.setonclicklistener (New View.onclicklistener () {

@Override
public void OnClick (View arg0) {
Alertdialog.builder Builder = new Alertdialog.builder (choiceactivity.this);
Set the icon for the title
Builder.seticon (R.DRAWABLE.IC_YXLM);
Set the contents of the title
Builder.settitle ("Enter the Game");
Set content to display a message
Builder.setmessage ("OK to choose to enter the game?") ");
Set up a Positivebutton
Builder.setpositivebutton ("OK", new Dialoginterface.onclicklistener ()
{
@Override
public void OnClick (Dialoginterface dialog, int which)
{
Toast.maketext (Choiceactivity.this, "Enter the game", Toast.length_short). Show ();
Intent intent=new Intent (choiceactivity.this,useractivity.class);
StartActivity (intent);//jump to the next interface useractivity

Finish ();
}
});
Set up a Negativebutton
Builder.setnegativebutton ("Cancel", new Dialoginterface.onclicklistener ()
{
@Override
public void OnClick (Dialoginterface dialog, int which)
{
Toast.maketext (Choiceactivity.this, "Continue selection", Toast.length_short). Show ();
}
});
Builder.show ();

}
});

}




This makes it possible to implement a dialog box!

This article is from the "Software Learning Summary" blog, be sure to keep this source http://bigcrab.blog.51cto.com/10626858/1685032

Android Aircraft Wars (iii) Popup dialog box

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.