Skip to content

Instantly share code, notes, and snippets.

@marteinn
Last active January 2, 2016 03:59
Show Gist options
  • Save marteinn/8247367 to your computer and use it in GitHub Desktop.
Save marteinn/8247367 to your computer and use it in GitHub Desktop.
How to delay opening of the keyboard on Android, put these methods in your activity.
private void showDelayedKeyboard (final View view) {
showDelayedKeyboard(view, 100);
}
private void showDelayedKeyboard (final View view, final int delay) {
new AsyncTask<Void, Void, Void>() {
@Override
protected Void doInBackground(Void... params) {
try {
Thread.sleep(delay);
} catch (InterruptedException e) {
}
return null;
}
@Override
protected void onPostExecute(Void result) {
InputMethodManager imm = (InputMethodManager) getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(view, InputMethodManager.SHOW_IMPLICIT);
}
}.execute();
}
/*
Usage:
showDelayedKeyboard(textField);
showDelayedKeyboard(textField, 300); // Delay in milliseconds
*/
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment