Create a class like CustomDialog.class,
and inside of it create a static method like the one below,
public static void ExitAppDialog(final Activity activity)
{
AlertDialog.Builder alertbox = new AlertDialog.Builder(activity);
alertbox.setTitle("Warning");
alertbox.setMessage("Exit Application?");
alertbox.setPositiveButton("Yes", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
activity.finish();
}
});
alertbox.setNegativeButton("No", new
DialogInterface.OnClickListener() {
public void onClick(DialogInterface arg0, int arg1) {
}
});
alertbox.show();
}
And in your activity's onBackPressed() call this method like this,
public void onBackPressed()
{
CustomDialog.ExitAppDialog(myActivity.this );
}
沒有留言:
張貼留言