Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to lose the focus of a edittext when "done" button in the soft keyboard is pressed?

I have 7 edittext boxes in my xml. I'm using the OnFocusChangeListener to read the value from edittext and i'm using that value for my calculation.I want to make my edittext to lose its focus when i click on the done button in the soft keyboard.so that i can get the value in the edittext.

like image 880
SSS Avatar asked Aug 16 '12 06:08

SSS


People also ask

How do you make EditText lose focus?

setOnClickListener(saveButtonListener); private OnClickListener saveButtonListener = new OnClickListener() { @Override public void onClick(View v) { Text1. clearFocus(); Text2. clearFocus(); findViewById(R. id.

How do I change the Done button on my Android keyboard?

First you need to set the android:imeOptions attribute equal to actionDone for your target EditText as seen below. That will change your 'RETURN' button in your EditText's soft keyboard to a 'DONE' button.


1 Answers

Call clearFocus method of EditText to lose focus when done button is clicked from soft-keyboard. do it as:

editText.setOnEditorActionListener(new OnEditorActionListener() {             @Override     public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {         if(actionId==EditorInfo.IME_ACTION_DONE){             //Clear focus here from edittext              editText.clearFocus();         }     return false;     } }); 

and also add android:imeOptions="actionDone" in edittext xml

like image 74
ρяσѕρєя K Avatar answered Sep 28 '22 08:09

ρяσѕρєя K