Is there a way to catch shift+enter events from android virtual keyboard? For now i am trying to use
private OnKeyListener editTextMessageKeyListener= new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(event.isShiftPressed())&&
(keyCode == KeyEvent.KEYCODE_ENTER))
{
addPhoneToList();
sendMessageToUsers();
return true;
}
return false;
};
};
But whenever I press enter or shift-enter, event.isShiftPressed() is always false... This time virtual keyboard shows that shift IS pressed, so somethere inside it there is a shift state maintain - how can i get it?
My phone is HTC Sensation with htc sense 3 default keyboard installed.
Related
i have been using dispatchKeyEvent to get the keycode of android keyboard but the problem is when i tap on Sym or Emoji button nothing happen, no keycode shows. this is the code i use to get the keycode:
#Override
public boolean dispatchKeyEvent(KeyEvent event) {
Toast.makeText(getBaseContext(), "key pressed : "+ String.valueOf(event.getKeyCode()), Toast.LENGTH_SHORT).show();
return super.dispatchKeyEvent(event);
}
Use KeyEvent.KEYCODE_PICTSYMBOLS for emoji.
/*
* Respond to soft keyboard events, look for the DONE press on the password field.
*/
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if ((event.getAction() == KeyEvent.ACTION_DOWN) &&
(keyCode == KeyEvent.KeyEvent.KEYCODE_PICTSYMBOLS))
{
// Done pressed! Do something here.
}
// Returning false allows other listeners to react to the press.
return false;
}
My application works with remote Bluetooth keyboard. I have defined some predefined custom implementation on arrow keys and enter key. I want to perform only those actions whenever user press arrow key or Enter Key in my application.
But sometimes it is still showing default behavior of keys.
My Current Code is as follows
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_UP) {
// my custom work
return true;
}else{
return super.onKeyUp(keyCode, event);
}
}
any idea, how I can restrict default behavior of arrow keys and enter key?
Thanks
Use below code:
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_UP || keyCode == KEYCODE_DPAD_LEFT || keyCode == KeyEvent.KEYCODE_DPAD_DOWN || keyCode == KEYCODE_DPAD_RIGHT || keyCode == KEYCODE_ENTER) {
// my custom work
return false;
}else{
return super.onKeyUp(keyCode, event);
}
}
I am trying to programmatically designate where the focus goes when a user presses the next button on the keyboard. I can get it to work for some, but I have one case where the view gets skipped and the view below it gets the focus.
I went into debugger and the focus does go through my view, but then jumps to the last one. Below is a small diagram of what I'm talking about.
(1) EditText
(2) AutoCompleteEditText
(3) EditText
(4) EditText
(1) -> (2) is ok
(2) -> (3) doesn't work, it does (2) -> (3) -> (4), where it briefly go to (3)
if I start at (3), then (3) -> (4) is ok.
This is how I am setting the focus
view.setOnKeyListener(new OnKeyListener()
{
#Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if((event.getAction() == KeyEvent.ACTION_DOWN) && (keyCode == KeyEvent.KEYCODE_ENTER))
{
view.clearFocus();
nextView.requestFocus();
return true;
}
return false;
}
});
view.setOnKeyListener(new OnKeyListener()
{
#Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
if((event.getAction() == KeyEvent.ACTION_UP) && (keyCode == KeyEvent.KEYCODE_ENTER))
{
view.clearFocus();
nextView.requestFocus();
return true;
}
return false;
}
});
Found the solution. If anyone else is having this issue, just change ACTION_DOWN to ACTION_UP so your code is only triggered when the press is complete. I'm guessing with ACTION_DOWN, there are multiple calls made. But I'm not sure.
Ok, so this is silly.
I am using a textbox with the input type textPassword.
On the Galaxy Tab 2 : 10.1 : I can not pick up the "Done" button as in an arrow pointing down then turning left.
I am doing the following check:
tv2.setOnKeyListener(new OnKeyListener() {
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (event.getAction() == KeyEvent.ACTION_DOWN)
{
switch (keyCode)
{
case KeyEvent.KEYCODE_DPAD_CENTER:
case KeyEvent.KEYCODE_ENTER:
performRegister();
return true;
default:
break;
}
}
return false;
}
});
The above code works correctly on 95% of devices that I have tried it is only the Galaxy Tab that is giving me this issue.
I have also tried :
tv2.setOnEditorActionListener(new OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
//CODE!!
}
});
But neither of these methods get called when I press the button. (Not called at all! It's not that I am not checking for the correct KeyEvent: There is no KeyEvent)
All that this button does is to hide the Keyboard.
Ps. I am using the Galaxy tab with the Samsung Chinese IME keyboard. v2.0.3
Thanks for any help:
Aiden
Try using
TextView.setImeOptions(EditorInfo.IME_ACTION_DONE);
then you should get a callback in your OnEditorActionListener
For my android app I have multiple edittexts on the main screen. If i have the first edittext in focus the menu/back buttons operate fine, if i have any of the other edittexts in focus than neither of them work at all. I'm not doing anything special regarding the menu/back buttons relative to that edittext, i'm not sure what the cause is? Has anyone run into a similar issue and/or know of the cause/solution?
Thanks!
I was have the same problem and I found solution for I was have OnKeyListener that return true; when I change it to return false; the problem was fixed
my_editText.setOnKeyListener(new OnKeyListener() {
#Override
public boolean onKey(View v, int keyCode, KeyEvent event) {
// you can use the next line to ensure back button & menu button will return false
if (event.getKeyCode() == KeyEvent.KEYCODE_BACK || event.getKeyCode() == KeyEvent.KEYCODE_MENU) return false;
// any other key you don't want to call other listener for it
if (event.getKeyCode() == KeyEvent.KEYCODE_ENTER&& event.getAction() == KeyEvent.ACTION_UP) {
return true;
}
return false;
}
});
OnKeyListener.onKey(android.view.View, int, android.view.KeyEvent)
easy fix for me, I had removed the only keyboard app.
just install a keyboard app and the buttons worked again