0

I am using one edittext in my application once I complete the input the keyboard wants to hide automatically without pressing back button. can anyone help me....

Durai
  • 11

4 Answers4

1

Try this code in your Edittext you will get option to close keyboard it self....

android:imeOptions="actionDone"

Gowthaman M
  • 8,057
  • 8
  • 35
  • 54
1

you should use TextWatcher to know when u complete typing, and then u can hide keyboard as below:

 EditText editText;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main);

    editText = (EditText)findViewById(R.id.editText);
    editText.addTextChangedListener(new TextWatcher() {
        @Override
        public void beforeTextChanged(CharSequence s, int start, int count, int after) {

        }

        @Override
        public void onTextChanged(CharSequence s, int start, int before, int count) {

            if(count == 5){

            InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(editText.getWindowToken(), 0);}

        }

        @Override
        public void afterTextChanged(Editable s) {

        }
    });

}

so in this code after typing five characters the keyboard will automatically hide.

Try it.

AKSHAY MANAGOOLI
  • 120
  • 2
  • 2
  • 21
1

Call this function whenever the input gets complete

InputMethodManager imm = (InputMethodManager) getSystemService(Activity.INPUT_METHOD_SERVICE);
//Hide:
imm.toggleSoftInput(InputMethodManager.HIDE_IMPLICIT_ONLY, 0);

private void hideKeyboard() {   
    // Check if no view has focus:
    View view = this.getCurrentFocus();
    if (view != null) {
        InputMethodManager inputManager = (InputMethodManager) this.getSystemService(Context.INPUT_METHOD_SERVICE);
        inputManager.hideSoftInputFromWindow(view.getWindowToken(), InputMethodManager.HIDE_NOT_ALWAYS);
    }
}
Mayur Kharche
  • 717
  • 1
  • 8
  • 27
1
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

editText.requestFocus();

imm.showSoftInput(editText, 0);

Try this (in editText you should put your own editText).