What I learned from Yu Song Momo's blog

Source: Internet
Author: User

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 );}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.