1. single choice list box
From: http://blog.csdn.net/xys289187120/article/details/6601613
Lertdialog. builder = new alertdialog. builder (maindialog. this); msinglechoiceid =-1; builder. seticon (R. drawable. icon); builder. settitle ("single choice"); builder. setsinglechoiceitems (mitems, 0, new dialoginterface. onclicklistener () {public void onclick (dialoginterface Diener, int whichbutton) {msinglechoiceid = whichbutton; showdialog ("the id you selected is" + whichbutton + ", "+ mitems [whichbutton]) ;}}); builder. setpositivebutton ("OK", new dialoginterface. onclicklistener () {public void onclick (dialoginterface Diener, int whichbutton) {If (msinglechoiceid> 0) {showdialog ("You selected" + msinglechoiceid) ;}}); builder. setnegativebutton ("cancel", new dialoginterface. onclicklistener () {public void onclick (dialoginterface dialog, int whichbutton) {}}); builder. create (). show ();
2. Multi-choice list box
From: http://blog.csdn.net/xys289187120/article/details/6601613
Alertdialog. builder = new alertdialog. builder (maindialog. this); multichoiceid. clear (); builder. seticon (R. drawable. icon); builder. settitle ("Multiple Choices"); builder. setmultichoiceitems (mitems, new Boolean [] {false, false}, new dialoginterface. onmultichoiceclicklistener () {public void onclick (dialoginterface dialog, int whichbutton, Boolean ischecked) {If (ischecked) {multichoiceid. add (whichbutton); showdialog ("the id you selected is" + whichbutton + "," + mitems [whichbutton]);} else {multichoiceid. remove (whichbutton) ;}}); builder. setpositivebutton ("OK", new dialoginterface. onclicklistener () {public void onclick (dialoginterface Diener, int whichbutton) {string STR = ""; int size = multichoiceid. size (); For (INT I = 0; I <size; I ++) {STR + = mitems [multichoiceid. get (I)] + "," ;}showdialog ("You selected" + Str) ;}}); builder. setnegativebutton ("cancel", new dialoginterface. onclicklistener () {public void onclick (dialoginterface dialog, int whichbutton) {}}); builder. create (). show ();
3. Set a keyboard event when editing edittext:
From: http://blog.csdn.net/xys289187120/article/details/6629450
Package CN. m15.xys; import android. app. activity; import android. OS. bundle; import android. view. keyevent; import android. view. inputmethod. editorinfo; import android. widget. edittext; import android. widget. textview; import android. widget. toast; import android. widget. textview. oneditexceptionlistener; public class keyboardactivity extends activity {@ override protected void oncreate (bundle savedinstancestate) {setcontentview (R. layout. keyboard); edittext edittext0 = paitest0); listener (New oneditexceptionlistener () {@ override public Boolean oneditexception (textview arg0, int arg1, keyevent arg2) {If (arg1 = editorinfo. ime_action_go) {toast. maketext (keyboardactivity. this, "you clicked the" go to "button on the keyboard", toast. length_short ). show () ;}return false ;}}); edittext edittext1 = paitest1); edittext1.setoneditexceptionlistener (New oneditexceptionlistener () {@ override public Boolean oneditexception (textview arg0, int arg1, keyevent arg2) {If (arg1 = editorinfo. ime_action_search) {toast. maketext (keyboardactivity. this, "you clicked the 'search' button on the keyboard", toast. length_short ). show () ;}return false ;}}); edittext edittext2 = paitest2); edittext2.setoneditexceptionlistener (New oneditexceptionlistener () {@ override public Boolean oneditexception (textview arg0, int arg1, keyevent arg2) {If (arg1 = editorinfo. ime_action_send) {toast. maketext (keyboardactivity. this, "you clicked the" send "button on the keyboard", toast. length_short ). show () ;}return false ;}}); edittext edittext3 = paitest3); edittext3.setoneditexceptionlistener (New oneditexceptionlistener () {@ override public Boolean oneditexception (textview arg0, int arg1, keyevent arg2) {If (arg1 = editorinfo. ime_action_next) {toast. maketext (keyboardactivity. this, "you clicked the 'Next' button on the keyboard", toast. length_short ). show () ;}return false ;}}); edittext edittext4 = paitest4); edittext4.setoneditexceptionlistener (New oneditexceptionlistener () {@ override public Boolean oneditexception (textview arg0, int arg1, keyevent arg2) {If (arg1 = editorinfo. ime_action_done) {toast. maketext (keyboardactivity. this, "you clicked the keypad 'complete' button", toast. length_short ). show () ;}return false ;}}); edittext edittext5 = paitest5); edittext5.setoneditexceptionlistener (New oneditexceptionlistener () {@ override public Boolean oneditexception (textview arg0, int arg1, keyevent arg2) {If (arg1 = editorinfo. ime_action_unspecified) {toast. maketext (keyboardactivity. this, "you clicked the" unspecified "button on the keyboard", toast. length_short ). show () ;}return false ;}}); super. oncreate (savedinstancestate );}}