Android

dialog example

tomato13 2011. 9. 21. 13:16

public class MainActivity extends Activity {

    /** Called when the activity is first created. */

    @Override

    public void onCreate(Bundle savedInstanceState) {

        super.onCreate(savedInstanceState);

        setContentView(R.layout.main);

        

AlertDialog.Builder builder = new AlertDialog.Builder(this);

builder.setMessage("Are you sure you want to move?")

      .setCancelable(false)

      .setPositiveButton("Yes", new DialogInterface.OnClickListener() {

          public void onClick(DialogInterface dialog, int id) {

          finish();

          }

      })

      .setNegativeButton("No", new DialogInterface.OnClickListener() {

          public void onClick(DialogInterface dialog, int id) {

               dialog.cancel();

          }

      });

AlertDialog alert = builder.create();

alert.show();

    }

}