Public class mainactivity extends activity {
@ Override
Protected void oncreate (bundle savedinstancestate ){
Super. oncreate (savedinstancestate );
Setcontentview (R. layout. activity_main );
Button btn1 = (button) findviewbyid (R. Id. button1 );
Btn1.setonclicklistener (New View. onclicklistener (){
@ Override
Public void onclick (view v ){
// Todo auto-generated method stub
Toast. maketext (getapplicationcontext (), R. String. Success, Toast. length_long). Show ();
Alertdialog. Builder = new alertdialog. Builder (mainactivity. This );
Builder. setmessage (R. String. Message)
. Settitle (R. String. Title)
. Setpositivebutton (R. String. OK, new dialoginterface. onclicklistener (){
@ Override
Public void onclick (dialoginterface arg0, int arg1 ){
// Todo auto-generated method stub
}
})
. Setnegativebutton (R. String. Cancel, new dialoginterface. onclicklistener (){
@ Override
Public void onclick (dialoginterface dialog, int which ){
// Todo auto-generated method stub
}
})
. Seticon (R. drawable. ic_launcher );
Dialog dialog = builder. Create ();
Dialog. Show ();
}
});
}
@ Override
Public Boolean oncreateoptionsmenu (menu ){
// Inflate the menu; this adds items to the action bar if it is present.
Getmenuinflater (). Inflate (R. Menu. Main, menu );
Return true;
}
}
Program: