Monday, January 23, 2012

Display an Alert Dialog

[sourcecode language="java"]
package com.my.option;

import android.app.Activity;
import android.app.AlertDialog;
import android.content.DialogInterface;
import android.os.Bundle;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;

public class OptionMenuActivity extends Activity {
/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main);

Button b = (Button) findViewById(R.id.button1);
b.setOnClickListener(new OnClickListener() {

@Override
public void onClick(View arg0) {
AlertDialog.Builder builder = new AlertDialog.Builder(OptionMenuActivity.this);
builder.setMessage("Do you really need to exit?");
builder.setCancelable(false);

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

@Override
public void onClick(DialogInterface arg0, int arg1) {
OptionMenuActivity.this.finish();

}
});

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

@Override
public void onClick(DialogInterface dialog, int arg1) {
dialog.cancel();

}

});

AlertDialog alert = builder.create();
alert.show();
}
});
}

}

[/sourcecode]

No comments:

Post a Comment

How to enable CORS in Laravel 5

https://www.youtube.com/watch?v=PozYTvmgcVE 1. Add middleware php artisan make:middleware Cors return $next($request) ->header('Acces...