Android: disable (or change of the function of ) the return key when AutoCompleteTextView is focused
My app has an AutoCompleteTextView used for searching. When it's in focus, I would like to disable or change the function of the return key to a specific function call. I tried in my layout xml to add the following property to the AutoCompleteTextView
android:imeOptions="actionDone"
But it works on my simulator (when you click enter, the keyboard disappears) but it doesn't work on my device (moto droidx running 2.3.3).
Can开发者_Python百科 someone show me how I can link the return key to a specific function (in my case, the search function) with android:imeOptions="actionGo"?
Write your code in setOnEditorActionListener
event of EditText
family. like
autoEditText.setOnEditorActionListener(new OnEditorActionListener() {
public boolean onEditorAction(TextView v, int actionId,
KeyEvent event) {
if (event != null&& (event.getKeyCode() == KeyEvent.KEYCODE_ENTER)) {
InputMethodManager in = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
// in.hideSoftInputFromWindow(autoEditText.getApplicationWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
//Commented line is for hide keyboard. Just make above code as comment and test your requirement
//It will work for your need. I just putted that line for your understanding only
//You can use own requirement here also.
}
return false;
}
});
Happy coding :)
For me it works if you add one more line about input type:
android:inputType="text"
android:imeOptions="actionDone"
精彩评论