How can I disable a tab key on a form so that it goes to the next button when press.
This is a hardware Tab key on a qwerty hardware keyboard.
You should implement the protected boolean onKeyDown(int keyCode, KeyEvent event) {}, check for the keyCode and if the key is tab, then consume the event.
Hope this helps!
Related
I'm trying to detect when the soft keyboard gets closed, I found this code snippet
#Override
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK){
//detects that keyboard was hidden
}
return super.onKeyPreIme(keyCode, event);
}
but this needs to be added to a subclass that extends editText, I'm not intrested in implementing the functionality I want to add on keyboard hidden in all my app, I want to add it for just one Activity, I tried onKeyDown, onKeyBack, onKeyUp, onBackPressed nothing seems to log the back press that closes the soft keyboard.
so my question is there a way to detect the click on the button that hides the keybaord?
I have a EditText that should not allow the user to input anything through the keyboard (soft or hard). This EditText should only allow the user to input something through keys(buttons) displayed in the screen by the app.
I have disabled the soft keyboard, but I can't find a way to disable the hardware keyboard input. This input via hardware keyboard can be done using a emulator that is configured to allow input through the hardware keyboard.
So, my question is, How can I block the input via physical keyboard in a EditText?
Thank you!
Finally got it!
Code:
editText.setOnKeyListener(new View.OnKeyListener() {
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
return true;
}
});
Explanation:
Returning true will tell the listener that I've already handled the hardware keyboard input. Based on Android documentation (http://developer.android.com/reference/android/view/View.OnKeyListener.html)
View.OnKeyListener: Interface definition for a callback to be invoked when a hardware key event is dispatched to this view. The callback will be invoked before the key event is given to the view. This is only useful for hardware keyboards; a software input method has no obligation to trigger this listener.
onKey(View v, int keyCode, KeyEvent event)
Called when a hardware key is dispatched to a view.
You could try these according to what you want in your xml layout
android:longClickable="false"
android:clickable="false"
android:cursorVisible="false"
android:editable="false"
Then make the edittext show what the user typed through the keyboard you made in the app.
I know that onTouchEvent()
can return the current touch point's x,y in a view,
However, when I touch a key on a softkeyboard.
the method is not working,
My question is how can I apply onTouchEvent to softkeyboard on Android?
It is not possible to get a touch event for a soft keyboard.
If you want to capture keys as they are entered into an EditText, check out the EditText.addTextChangedListener() function.
Alternatively, try implementing the View.OnKeyListener interface in your Activity, or overriding public boolean dispatchKeyEvent(KeyEvent e), or overriding public boolean onKeyDown(int keyCode, KeyEvent event). In all of those cases, you can check what the keyCode or KeyEvent is and handle it as you wish.
I am using a device having keypad(Hardware) attached on phone device.Now I want to get the event after clicking OK button on keypad.
i found we use DPAD_CENTER for specifiying OK Button.
Can anyone helps me on this. How set listener for this OK button. Thanks
Override onkeydown function and you can do actions for whichever hardware key is pressed
public boolean onKeyDown(int keyCode, KeyEvent event){
if(keyCode==KeyEvent.KEYCODE_DPAD_CENTER){
// Do what you have to do here
}
return false;
}
How can I capture the hardware keyboard events without using an EditText field?
For example, in a simple activity the display a square on the screen, when a "B" is pressed on the slide keyboard I want to turn it blue, when a "G" is presses, turn it Green, etc.
I don't need help with the color code, just how to intercept the keypress
This is not about the soft or virtual keyboard
Android classes usually provide event handlers, you can implement when subclassing them. The Activity class has the following event handlers:
onKeyDown(int keyCode, KeyEvent event)
onKeyLongPress(int keyCode, KeyEvent event)
onKeyMultiple(int keyCode, int repeatCount, KeyEvent event)
onKeyShortcut(int keyCode, KeyEvent event)
onKeyUp(int keyCode, KeyEvent event)
In addition all views have the following event handlers:
onKeyDown(int, KeyEvent)
onKeyUp(int, KeyEvent)
I guess there are many other classes that have similar event handlers for key events, but this should be enough for your situation. The KeyEvent then contains information about the pressed key, i.e. the key code.
Activity class has already implemented KeyEvent.CallBack see here
you just need to override these methods and implements all events that you want