Last active
January 2, 2016 03:59
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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