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