3

In my activity there is three editText view it will randomly gets hide at some time
After entering a single text in the editText the soft-keyboard will disappears automatically
Now I want to show the soft keyboard When editText get focused
How to do this?
Thanks in advance

user3251646
  • 248
  • 3
  • 15

2 Answers2

2

Through InputMethodManager you can show and hide the soft keyboard. Use toggleSoftInput() method to show soft keyboard when EditText get focus and use hideSoftInputFromWindow() to hide the keyboard when EditText lost focus as below...

InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);

editText.setOnFocusChangeListener(new View.OnFocusChangeListener() {
    @Override
    public void onFocusChange(View v, boolean isFocused) {

        if (isFocused) {

            imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
        } else {

            imm.hideSoftInputFromWindow(getWindow().getCurrentFocus().getWindowToken(), 0); 
        }
    }
});
Hamid Shatu
  • 9,193
  • 4
  • 28
  • 40
1

Try with these code..

InputMethodManager inputMethodManager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
if (inputMethodManager != null) {
    inputMethodManager.toggleSoftInput(InputMethodManager.SHOW_FORCED, 0);
}
Nagendra Badiganti
  • 1,566
  • 2
  • 18
  • 28