The oneditexception listening event in EditText is executed twice,

Source: Internet
Author: User

The oneditexception listening event in EditText is executed twice,

Android EditText uses setoneditexceptionlistener to set a listening event for the text editing box. However, the logic in oneditexception triggers the event twice after each carriage return, this method is triggered when the ACTION_UP and ACTION_DOWN values of the keyboard press enter are used. Therefore, the following code is modified to prevent two executions:

1 public boolean oneditequaltion (TextView v, int actionId, KeyEvent event) {2 // The following method prevents two requests from sending 3 if (actionId = EditorInfo. IME_ACTION_SEND | 4 (event! = Null & event. getKeyCode () = KeyEvent. KEYCODE_ENTER) {5 switch (event. getAction () {6 case KeyEvent. ACTION_UP: 7 // send request 8 String keyWord = et_search.getText (). toString (). trim (); 9 if (null = keyWord) 10 keyWord = ""; 11 dismisspopup (); 12 LogUtils. d ("Send search request to server:" + keyWord); 13 // initiate query 14 searchByKeyWord (keyWord); 15 hideSoftInput (); 16 return true; 17 default: 18 return true; 19} 20} 21 return false; 22}

 

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.