2

I want to do the following. User should be able to input one letter (only letter) from standard keyboard (hardware or software). If he is typing another letter, then the previous letter should be replaced with this one. So only the current letter should be displayed. User should be able to dismiss this dialog and get back to activity. And if he clicked "done" button in keyboard the activity should know what letter he entered.

So I thought about alert dialog and edit text with some extensions to display only current char. This is easy.

However, and this gets me mad already, although edit text is in focus the keyboard does not appear on the screen until edit text is clicked. Why is that so? It should be, should it not?

I won't take something like the following for the answer, because I shouldn't have to do it manually. It should be automatic. Besides, I'm not sure how this would work with a hardware keyboard.

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

I want to know why exactly the keyboard is not shown after edit text has focus? And what should I do to get this functionality without manually enabling and disabling software keyboard.

Spencer Williams
  • 902
  • 8
  • 26
user1685095
  • 5,787
  • 9
  • 51
  • 100

2 Answers2

0

Use this.

EditText yourEditText= (EditText) findViewById(R.id.yourEditText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);
Manish Sharma
  • 2,406
  • 2
  • 16
  • 31
  • Did you read my question? I said I wont take this workaround as an answer. I want to know why this is happen. Should it happen? – user1685095 Jul 17 '13 at 14:19
  • Well, the way the question was originally phrased makes it unclear as to whether you won't take this as an answer or you want to take this as an answer. – Spencer Williams Oct 22 '13 at 17:06
0

For your information, see this related question: Why the soft keyboard shows or not when an activity starts?. You can read it as an alternative by enclosing your EditText into a ScrollView.

But it's not more satisfying than the well known workaround (manually enabling the software keyboard) because we don't understand why it works better in this case...

Community
  • 1
  • 1
Tok'
  • 565
  • 8
  • 11