Keyboard doesn't show up when EditText is in focus - android

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.

Use this.
EditText yourEditText= (EditText) findViewById(R.id.yourEditText);
InputMethodManager imm = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(yourEditText, InputMethodManager.SHOW_IMPLICIT);

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...

Related

Getting keystrokes from the soft keyboard from within a fragment

I have an activity that launches a fragment whose main purpose is to present the user with an Imagebutton that they can click to launch the soft keyboard and type in whatever text they like. I need to grab each key as it is pressed on the soft keyboard. However, the user is not typing into an EditText view so I am struggling a bit with this. I can successfully display the soft keyboard when the user clicks the ImageButton using the code below...
InputMethodManager imm = (InputMethodManager) getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);
imm.toggleSoftInput(InputMethodManager.SHOW_FORCED, InputMethodManager.HIDE_IMPLICIT_ONLY);
However, I have not been able to find an example or a method that would let me grab the keystrokes from the soft keyboard without an EditText. I assume this must be possible I just don't know how to go about it.
Maybe it helps if you implement your own InputMethodService? You can overwrite the onUpdateSelection() method, which is called every time when a key is touched on the softkeyboard.

Using a custom keyboard to enter and manipulate data in EditText

I want the user to enter data in an EditText using a custom keypad. The custom keypad is integrated to the layout. It is not supposed to pop up when the EditText in question is in focus.
The problem I have is that I can't disable the soft keyboard without disabling the editing properties of the EditText: I want the user to be able to position the cursor for example.
I have tried using the InputMethodManager
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
but it doesn't work at least on some OS versions. The keyboard still pops up when I tap the EditText.
I have also tried setting the input mode:
edtView.setInputType(0)
but then I cannot position a cursor. I could Selection.setSelection(Spannable txt, int index); to position the cursor, but how to know the position the user has touched?
I never tried this myself, but the only thing that occurs to me is: have you tried adding an OnEditorActionListener to your EditText and calling hideSoftInputFromWindow every time you get an editor action?

Android onscreen keyboard without any other keyboard

I've looked at several questions and come across several posts, but i'm not able to figure out how to do this.
The following picture shows you the basic layout :
I've created a custom numpad and put it up on the repo.
Currently, when the app opens, the edit text has the focus but and anything i enter with the keyboard will go into the edittext box. This part of the functionality works fine.
Problem: When i touch the edittext again, system Input Method with its huge keyboard pops up. How do i completely block it from popping up? Or, can i tell the app to use only my keyboard instead of the system one? (Or is the only way to write a custom ime?)
i cannot use NULL type input at the manifest because doing that makes the caret in the edittext disappear and moreover if there are two edit texts, i wouldnt know which has focus.
Any help would be highly appreciated!
You can do a few things:
Programmatically hide it in the whole app:
getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);
Hide it from the view it would be attached to:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(yourEditText.getWindowToken(), 0);
Set the input type of the EditText to 0:
EditText yourEditText=(EditText)findViewById(R.id.editTextConvertValue);
yourEditText.setInputType(0);

Soft keyboard won't appear

Hello
I want to show up the soft keyboard whenever I tap on the textfield. the application of mine works fine whenever u login for the first time but when i logout from the application
it does not pop up.
You can show the soft keyboard focused on a specific EditText like this.
EditText editText = (EditText) findViewById(R.id.edit);
InputMethodManager imm = (InputMethodManager) getSystemService(
Context.INPUT_METHOD_SERVICE);
imm.showSoftInput(editText, InputMethodManager.SHOW_IMPLICIT);
I have ran into this many a time. Please resist to force the keyboard to show. Any device that has a physical hard keyboard will not show in many different kinds of views. Try running your application on a devices that are not connected to a bluetooth keyboard and does not have a hard keyboard.
EditText should handle this for you, post some of your code and maybe we can help figure out why it is not doing so. Or you can force the soft keyboard to show by doing something like this:
InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.showSoftInput(yourEditText, 0);
If you put that inside the onClick() method for an OnClickListener that you set on your EditText then it will force the keyboard open whenever the EditText is clicked.

Android keyboard

My application starts with a bunch of text input fields, and I want that when starting up the the application. The virtual keyboard isn't open, but opens only when I click on one of the textinput fields.
How do I do this?
In your onCreate method you could get your first text view and call requestFocus() on it. This ought to focus this field when the activity starts and bring up a virtual keyboard if needed.
If you want the keyboard not to appear on startup, request focus for a non-text element like a button.
You should leave the input method to the user. They might be using a physical keyboard or maybe even something like speech to text.
I've used this approach to hide the keyboard after the user searches. You could use this in our onCreate method:
Close/hide the Android Soft Keyboard
Quote from Reto Meier's accepted solution:
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);

Categories

Resources