Reputation: 1051
I got a edit text and a save button , i want to close the keypad on clicking save button instead of pressing back key, keypad has to be closed after i enter save button. How to achieve this please help me and thanks in advance
Upvotes: 3
Views: 3708
Reputation: 331
The follow solution is for the Xamarin friends...
NOTE: This is when at least a character was typed and then the 'Enter' key pressed.
private SearchView _searchView;
public override bool OnCreateOptionsMenu(IMenu menu)
{
//Do things here... Call MenuInflater......
_searchView.QueryTextSubmit += _searchView_QueryTextSubmit;
}
void _searchView_QueryTextSubmit(object sender, SearchView.QueryTextSubmitEventArgs e)
{
InputMethodManager imm = (InputMethodManager)GetSystemService(InputMethodService);
imm.HideSoftInputFromWindow(_searchView.WindowToken, HideSoftInputFlags.None);
e.Handled = true;
}
Upvotes: 1
Reputation: 31963
You can override onkeypress on your edittext and check if the enter was pressed and if true then hide
myEditText.setOnKeyListener(new OnKeyListener() {
@Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
}
return false;
}
});
Upvotes: 6