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