How can I set the focus (and display the keyboard) on my EditText programmatically How can I set the focus (and display the keyboard) on my EditText programmatically android android

How can I set the focus (and display the keyboard) on my EditText programmatically


Try this:

EditText editText = (EditText) findViewById(R.id.myTextViewId);editText.requestFocus();InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);

http://developer.android.com/reference/android/view/View.html#requestFocus()


use:

editText.requestFocus();InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);


This worked for me, Thanks to ungalcrys

Show keyboard:

editText = (EditText)findViewById(R.id.myTextViewId);editText.requestFocus();InputMethodManager imm = (InputMethodManager)getSystemService(this.INPUT_METHOD_SERVICE);imm.toggleSoftInput(InputMethodManager.SHOW_FORCED,InputMethodManager.HIDE_IMPLICIT_ONLY);

Hide keyboard:

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