Android edittext or autocompletetextview setonkey event

Source: Internet
Author: User

Modify the project today and change the homepage search. After the user enters the keyword, press the software keyboard and press enter to jump to the result page.

CodeNo problem. I don't know why I always jump to the secondary node. debug debugging found that the second step of setonkeylistener execution had not been found to solve the problem.

Finally, I checked the API of the Chinese version and found a setoneditexceptionlistener event.

I changed the search event setonkeylistener to setoneditexceptionlistener.

Then change XML

 
<Edittextandroid: Id = "@ + ID/searbox" style = "@ style/indexsearchbox" Android: layout_toleftof = "@ ID/searchbtn" Android: hint = "@ string/pleasekey" Android: layout_height = "45dip" Android: singleline = "true" Android: imeoptions = "actiongo"/> indicates changing the Enter key on the software keyboard to go

Code:

// Click the software keyboard carriage return event

// Click the press ENTER event txtkeyword. setoneditexceptionlistener (New edittext. oneditexceptionlistener () {@ overridepublic Boolean oneditexception (textview V, int actionid, keyevent event) {// todo auto-generated method stubif (actionid = editorinfo. ime_action_go) {// jump activityreturn true;} else {toast. maketext (context, R. string. key_word, toast. length_short ). show (); Return true ;}} return false ;}});

The test and debugging are successful.

The second question of this jump is a few hours ....

 

Related Article

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.