Samsung Galaxy Tab 2 : 10.1 - Can't pick up "Enter" - android

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

Related

I am not getting the event when long press on power button on android 6.0

I have implemented onKeyDown function in my activity and i want to open a dialog if we long press on power button. I have implemented that function as per following manner and working fine on older versions of android but isn't working on android 6.0
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
switch(keyCode){
case KeyEvent.KEYCODE_POWER :
if(event.isLongPress()){
//Do something
return true;
}
break;
default :
break;
}
return super.onKeyDown(keyCode, event) ;
}
Can you please help me.

Android: catching action for keyboard enter button being pressed

I am trying to respond to pressing the enter button on a standard system on screen soft keybord, in numeric mode. keyboard appears on the screen when myCustomEditText class is given focus.
tried 2 approaches:
overriding onKeyDown():
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
//do sth..
return true;
}
return super.onKeyDown(keyCode, event);
}
setting listener setOnKeyListener:
myCustomEditText.setOnKeyListener(new OnKeyListener() {
public boolean onKey(View v, int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_ENTER) {
onRightButtonClicked();
return true;
}
return false;
}
});
(also tried onKeyDown() in myCustomEditText as well, but with no effect)
problem is:
these aproaches above works for all the keys being pressed but for the enter key - the methods are not even being fired at all. (it's not a problem of bad KeyEvent.KEYCODE_...)
my question is:
why these methods are not being fired for enter key, but are for other keys, and how to listen to enter key being pressed properly?
You respond to ENTER differently than normal keys, try something like this:
editText.setOnEditorActionListener(new TextView.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
switch (actionId) {
case EditorInfo.IME_ACTION_DONE:
...
return true;
default:
return false;
}
}
});
You can specify which action is performed by ENTER by specifiying android:imeOptions in XML or by calling editText.setImeOptions(...) with one of the constants in EditorInfo. imeOptions also changes how the ENTER key looks! For example if you set imeOptions to actionSearch then the ENTER key will look like a search button.
You can find a list of all possible values for imeOptions along with a description here.

catching the "OK" button vs pressing "round-arrow" on EditText in Android

I have an EditText with android:inputType="phone" keybord. There is an "OK" on this keyboard. I like to catch pressing this OK btn. However I don't know the key event. I would like to use code like this:
setOnKeyListener(new OnKeyListener()
{
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:
case KeyEvent.?????????? <- this one please
return true;
default:
break;
}
}
return false;
}
});
I hope the code is different from pressing the "round-arrow"!
I checked all the key events in the docs but could not find anything.
Thanks
The 'OK' button is usually associated with finishing the input, and is different from the others. Use setOnEditorActionListener to catch it:
editText.setOnEditorActionListener( new OnEditorActionListener()
{
public boolean onEditorAction( TextView v, int actionId, KeyEvent event )
{
// Do what you want to do here
}
});

when i click on "DONE" button on softkeybord how to go next activity android

when i click on softkeyboard my keyboard getdown or hide but i want to go to next activity when i click on "done " button on keyboard of android.so how to do it?
and my next qus is if i have 2 edit box in my layout when i click on first edit box then in my soft keyboard "next " would appear for going to next text box and when i go to second text box it change to "done".
thanks in advance....
x
Its is better to add some button in the layout as all android phones dont provide a consistent behaviour when using imeoptions.
This seems to be a bug. Different manufacturers make a customized keyboard for their phone which may not completely behave as the android standard keyboard. This issue has been raised before. Most people overcome this issue by either overiding the onKey event or using a TextWatcher class. A bug has been filed about this
http://code.google.com/p/android/issues/detail?id=2882
You can use a listener to check for imeoptions
incomeInput.setOnEditorActionListener(new EditText.OnEditorActionListener() {
#Override
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE){
//Do your stuff here
return true; // mark the event as consumed
}
return false;
}
}
You need to implement OnEditorActionListener interface.
Code looks like :
public class Main extends Activity implements OnEditorActionListener {
#Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.main1);
}
public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {
if (actionId == EditorInfo.IME_ACTION_DONE) {
startActivity(new Intent());
return true;
}
return false;
}}
Use setOnKeyListener with your second EditText and in onKey method do something like this.
#Override
public boolean onKey(View v, int keyCode, KeyEvent event)
{
// TODO Auto-generated method stub
if(keyCode == KeyEvent.KEYCODE_ENTER && event.getAction() == KeyEvent.ACTION_DOWN)
performYourAction();
return false;
}
I hope it will be helpfull for you.

Android virtual keyboard - catch Shift+enter events

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.

Categories

Resources