Reputation: 16781
I have an EditText
and I need it to lose focus and make the keyboard disappear when the user presses 'Done' on the keyboard. My code goes like:
etFromCustom.setOnEditorActionListener(new OnEditorActionListener() {
@Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
((LinearLayout) findViewById(R.id.linlay_dummy)).requestFocus(); //this is what I have to do - send focus to a dummy layout
return true;
}
return false;
}
});
I know that, by default, the 'Done' key on the keyboard hides the software keyboard, but since I overrode it it doesn't work anymore: the EditText
does lose focus, but the keyboard, instead of disappearing, just turns from numeric one to qwerty one.
Upvotes: 1
Views: 485
Reputation: 2751
try the following code
put in create activity
private InputMethodManager imm;
imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
DoneButton.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
// TODO Auto-generated method stub
try {
// yourEditTextView.setText("");
imm.hideSoftInputFromWindow(
searchEditTextView.getWindowToken(), 0);
} catch (Exception e) {
e.printStackTrace();
}
}
});
Upvotes: 0
Reputation: 3261
Try this,
Add this code in your xml. particular EditText
in you xml file.
android:imeOptions="actionDone"
Upvotes: 1