How to detect if the keycode_numpad_dot is clicked in Android? - android

I'm a newbie on this language. I am struggling on this problem detecting if the keycode_numpad_dot is clicked.

For numpad dot use:
KeyEvent.VK_DECIMAL
Sample code:
public boolean onKeyDown(int keyCode, KeyEvent event)
{
if (keyCode == KeyEvent.VK_DECIMAL)
return true;
else return super.onKeyDown(keyCode, event);
}
Android Key Code:
key 83 NUMPAD_DOT

Related

How to obtain the currently selected View onKeyDown method?

I'm trying find if a specific View is selected following a key press. For this purpose I was trying to use the onKeyDown method on my main activity.
I already tried to set a setOnKeyListener on the fragment but it wasn't registering any input.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
// Check if it's selecting a specific View
}
return super.onKeyDown(keyCode, event);
}
Any idea how I could do this?
one from many approach that may use, fun n silly maybe, but it was work for me
on Global declaration
Integer iLastView=0;
on View that selected before
iLastView=iView;
and last in the inKeyDown
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DPAD_DOWN) {
if(iLastView==iView1){
//something here
}else if(check){.....}
}
return super.onKeyDown(keyCode, event);
}

Disable Back button in Digits

While doing digits programming, i am using following method :
Digits.authenticate(authCallback,R.style.CustomDigitsTheme1);
which directs me to digits authentication screen(without showing my xml design file).
Now, when i press back button, it shows me my xml with digits auth button as below.
which i do not want.I tried conventional ways of disabling back buttons but they did not work. Is there any way i can disable back button on authentication???
You can override when the keyboard disappears using this method:
public boolean onKeyPreIme(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK &&
event.getAction() == KeyEvent.ACTION_UP) {
// Do your thing here
return false;
}
return super.dispatchKeyEvent(event);
}
This may helps you.
Try Using these
#Override
public void onBackPressed() {
// your code.
}
and for older then API 5 use this:
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// your code
return true;
}
return super.onKeyDown(keyCode, event);
}

Is there something wrong with onKeyUp (down) with API=22?

I don't get if this is a bug. I used to catch key press events on the menu button, and noticed that - after switching to v22 and building with 22.0.1 - it didn't work anymore.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
Log.i("keydown", "generic");
if (keyCode == KeyEvent.KEYCODE_MENU) { Log.i("keydown", "menu"); }
return super.onKeyDown(keyCode, event);
}
#Override
public boolean onKeyUp(int keyCode, KeyEvent event) {
Log.i("keyup", "generic");
if (keyCode == KeyEvent.KEYCODE_MENU) { Log.i("keyup", "menu"); }
return super.onKeyUp(keyCode, event);
}
My console stays empty. Any ideas? Both on why and on how to workaround.
Yep there is something wrong - bug has been recognized and its fix has been set on a future release of appcompat-v7. It is related to AppCompatActivity and should not affect the framework Activity of course.
See here for reference.

How to listen the keypress in the soft keyboard?

I need a listener to identify the keypress in the soft keyboard/on screen keyboard.
I tried with addtextchangelistener textwatcher but this one give the good result but it shows the change also when some text is pasted into it.
I need to identify only the key press by the user.
Is there any possible way to detect the key press.
see this keyevent and use following code to identify which key is pressed by Users.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK)
{
// Do Code here
}
else if(keyCode == KeyEvent.KEYCODE_0)
{
}
else if(keyCode == KeyEvent.KEYCODE_1)
{
}
return super.onKeyDown(keyCode, event); }
When handling keyboard events with the KeyEvent class and related
APIs, you should expect that such keyboard events come only from a
hardware keyboard. You should never rely on receiving key events for
any key on a soft input method (an on-screen keyboard).
see: Handling Keyboard Actions
See this if can help you.
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK && event.getRepeatCount() == 1) {
finish();
return true;
}
return super.onKeyDown(keyCode, event);
}
#Override
public boolean onKeyDown(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK) {
// Do Code here
}
return super.onKeyDown(keyCode, event);
}

Android long key press

I need to generate/trigger a long key press event of a button in Android.
Any help regrading this?
From Android 2.0, Activity contains the method
public boolean onKeyLongPress(int keyCode, KeyEvent event)
For exemple, a long key press on the back button would be :
#Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK)
{
// do your stuff here
return true;
}
return super.onKeyLongPress(keyCode, event);
}
Take a look at this article.
You can set Long key press on button like:
btnNext.setLongClickable(true);
btnNext.setOnLongClickListener(l)

Categories

Resources