Android keypad Control

Source: Internet
Author: User

The case of "EditText + Button" forming an "input + Button response" is most common in android programming.
 
Note the following details:
 
After inputting EditText, click the Button to request the data. The keyboard should disappear on its own.
After inputting EditText, you can directly click "enter" on the keyboard instead of clicking the Button to send a request. Then, you should be able to respond to the request normally.
For problem 1, you can actively hide the soft keyboard in response to the onClick event of the Button and add the following code.
[Java]
InputMethodManager imm = (InputMethodManager) getSystemService (Context. INPUT_METHOD_SERVICE );
Imm. hideSoftInputFromWindow (mEditText. getWindowToken (), 0 );
For question 2, you can find the answer in the EditText api doc.
Void android. widget. TextView. setoneditexceptionlistener (oneditexceptionlistener l)
Set a special listener to be called when an action is saved med on the text view. this will be called when the enter key is pressed, or when an action supplied to the IME is selected by the user. setting this means that the normal hard key event will not insert a newline into the text view, even if it is multi-line; holding down the ALT modifier will, however, allow the user to insert a newline character.
 
Parameters:
L
Therefore, you only need to set an oneditexceptionlistener for EditText. A simple example is as follows:
[Java] www.2cto.com
// The action listener for the EditText widget, to listen for the return key
Private TextView. oneditexceptionlistener mWriteListener =
New TextView. oneditexceptionlistener (){
Public boolean oneditexception (TextView view, int actionId, KeyEvent event ){
// If the action is a key-up event on the return key, send the message
If (actionId = EditorInfo. IME_NULL & event. getAction () = KeyEvent. ACTION_UP ){
String message = view. getText (). toString ();
SendMessage (message );
}
If (D) Log. I (TAG, "END oneditexception ");
Return true;
}
};
Note: The second parameter actionId of the TextView. oneditexceptionlistener interface method oneditexception method can be found in the description of EditorInfo. List as follows


IME_ACTION_DONE
IME_ACTION_GO
IME_ACTION_NEXT
IME_ACTION_NONE
IME_ACTION_PREVIOUS
IME_ACTION_SEARCH
IME_ACTION_SEND
IME_ACTION_UNSPECIFIED


From the column of volcano brother

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.