Using a custom keyboard to enter and manipulate data in EditText - android

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?

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.

Keyboard doesn't show up when EditText is in focus

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

How to disable EditText's keyboard and cursor functions..?

I making an application with my own keyboard and I want to completely DISABLE the android default virtual keyboard.
I tried this:
myEditText.setOnClickListener(new OnClickListener()
{
public void onClick(View v)
{
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(keresetEditText.getWindowToken(), 0);
}
});
It is working very well, but accidently I just found an error that really bugs me to the hell:
When I slide down my finger on the EditText the soft keyboard just appear!
So the conclusion is: the onClickListener just not running while i slide, and not tap.
I tried onTouchListener, but it just didn't work!
Any tips how could I completely disable virtual keyboard ? I don't need it in the entire application.
Other thing:
I could make an other question to stackoverflow but I think its logical here so:
When I click on the EditText's cursor, i can move it in the text inside my EditText, but i dont want it to enabled like this. Can I disable the cursors MOVEability ??? So i need the blinking cursor but just totally in stayed position.
Here are few solutions for you:
if you will never need the softkeyboard to show on that activity, you can set the android:windowSoftInputMode="stateAlwaysHidden" attribute in manifest
disable the edit text. You will not have the blinking cursor (or any cursor at all), but it will be impossible to open the soft keyboard using a disabled edit text, while still being able to set your own text in code
just use a TextView, while setting as background android.R.drawable.edit_text .It will look like an EditText, while only being a read-only TextView, still allowing you to set any value from code. Again, you still don't have the blinking cursor
set the EditText's focusable and clickable attributes to false. The edit text will never receive focus, thus never causing the soft keyboard to show
(this is a hack) place an invisible button over the edittext, so a click over the edittext will actually be intercepted by the button that does nothing. The edit text will still be focusable using the trackball or direction keys, and you still won't have the blinking cursor

Forcefully bring android soft keyboard without any edit fields

I know we can bring the soft keyboard in android with any edit fields. I need to know whether it is possible to bring soft keyboard without any edit fields such as, on click of a button.
On click of a button, I need to bring the soft keyboard and monitor the key press events. Is there a way to bring soft keyboard on click of button?
well, the standard way of bringing up the soft keyboard is
InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.toggleSoftInput(0, 0);
However, I've always used it to bring it up in conjunction with a EditText component. But I believe if you put that code in the click listener for the button, the keyboard should show up.
Try this
InputMethodManager inputMgr = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
inputMgr.showSoftInput(View youredittextobject, InputMethodManager.SHOW_FORCED)
In above code the first argument is of the edittext object view that you need to pass for which you want the keyboard to show up

How to remove default keyboard from emulator in android?

m surffing from one proble. in my project layout i put one edit text to put the text from search data from the database but when i write in edit text that time default keyboard opens so i want to hide this keyboard
Using InputMethodManager, you can force android to hide/show the keyboards.
Calling hideSoftInputFromWindow, passing in the token of the window containing your edit field.
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
With this you will not see the keyboard at all.

Categories

Resources