[Bloggers: Dear bloggers, netizens, and everyone else! Welcome to this blog. You are welcome to have more exchanges, give more comments, learn from each other, and make mutual progress. Our slogan is: study hard and make progress every day .]
This application is widely used. Basically every application needs it. When you click the back key on your mobile phone, a dialog box is displayed, and you can select "OK" or "cancel ".
Next, let's talk about how the program captures the back key. When the user clicks the back key, the execution program will be triggered.
Capture method:
/** <Br/> * capture back <br/> */<br/> @ override <br/> Public Boolean onkeydown (INT keycode, keyevent event) {<br/> If (keycode = keyevent. keycode_back & event. getrepeatcount () = 0) {<br/> exitdialog (mainactivity. this ). show (); <br/> return true; <br/>}</P> <p> return Super. onkeydown (keycode, event); <br/>}
The pop-up dialog implementation is as follows:
/** <Br/> * The system exits. <br/> * @ Param context <br/> * @ return <br/> */<br/> private dialog exitdialog (context context) {<br/> alertdialog. builder = new alertdialog. builder (context); <br/> builder. seticon (R. drawable. icon); <br/> builder. settitle ("system information"); <br/> builder. setmessage ("are you sure you want to exit the program? "); <Br/> builder. setpositivebutton ("OK", <br/> New dialoginterface. onclicklistener () {<br/> Public void onclick (dialoginterface dialog, int whichbutton) {<br/> finish (); <br/>}< br/> }); <br/> builder. setnegativebutton ("cancel", <br/> New dialoginterface. onclicklistener () {<br/> Public void onclick (dialoginterface dialog, int whichbutton) {<br/>}< br/>}); <br/> return builder. create (); <br/>}
Application is very simple, hope to help you, reprint Please note: http://blog.csdn.net/richway2010