Use KeyEvent in Button onClick

0

I want to use KeyEvent example KEYCODE_0 Link in button onClick

<Button
              android:id="@+id/Btnequal_id"
              android:layout_width="wrap_content"
              android:layout_height="60dp"
              android:layout_weight="1"
              android:onClick="0x00000007"
              android:text="=" />
android
onclick
keyevent

2 Answers

1

get instance of your EditText on which you wanna apply keyEvent listener,then setOnKeyListner on your edittext like below.

mPinBox4 = (EditText) findViewById(R.id.pinVerifyBox4);

    mPinBox4.setOnKeyListener(new View.OnKeyListener() {
        @Override
        public boolean onKey(View v, int keyCode, KeyEvent event) {

            if (keyCode==KeyEvent.KEYCODE_0){
                //excute what ever you want when KEYCODE_0 is pressed
            }
            return false;
        }
    });

You can up vote my answer if it works for you.Thanks

answered on Stack Overflow Mar 9, 2016 by Arora
0

onKeyEvent can be applied on EditText.I think you are asking wrong question. Please clear me if ,Iam wrong.

answered on Stack Overflow Mar 8, 2016 by Arora

User contributions licensed under CC BY-SA 3.0