0

Clicking on an EditText, the device displays the keyboard. Is there any way, in code, I can simulate a key press? I want to use it to click on the button that changes the alphabetical keyboard pad.

Andrew Schuster
  • 3,229
  • 2
  • 21
  • 32
Sebosin
  • 167
  • 6
  • 16

4 Answers4

4

View.dispatchKeyEvent for example

stefan bachert
  • 9,413
  • 4
  • 33
  • 40
1

already tried smth like this?

Instrumentation inst = new Instrumentation();
            for ( int i = 0; i < 10; ++i ) {
                inst.sendKeyDownUpSync(KeyEvent.KEYCODE_MENU);
                Thread.sleep(2000);
                inst.sendKeyDownUpSync(KeyEvent.KEYCODE_BACK);
                Thread.sleep(2000);
            }

like original author wrote there

hope you find it useful..cheers

Community
  • 1
  • 1
Ewoks
  • 12,285
  • 8
  • 58
  • 67
1

Is your goal to change the type of keyboard that is displayed (e.g. numeric instead of alphabet)?

If that's what you're going for, you can simply set the "numeric" property on the TextView.

ravuya
  • 8,586
  • 4
  • 30
  • 33
0

Your app cannot manipulate the IME keyboard like that. You need to set the input type in code and let the device do what it wants to do. This question looks very similar to your other question: ANDROID - Numeric keyboard

Community
  • 1
  • 1
Mark D
  • 3,317
  • 1
  • 26
  • 27