0

How can I trigger the software keyboard and add listeners to it's keys?

3 Answers 3

3

To display the soft keyboard you might try: InputMethodManager.showSoftInput()

As for adding listeners, the best you can do is add a TextChangedListener to an EditText to listen to the changes in the EditText view that are made via the keyboard.

Sign up to request clarification or add additional context in comments.

5 Comments

Ive tried to do something like that: on pressing long menu button while i`am in map view, to show me the soft keyboard.. but as i press menu, the application crush: this is whhat i write in my proggy:
InputMethodManager showSoftInput; public boolean onKeyDown(int keyCode, KeyEvent event) { switch (keyCode) { case KeyEvent.KEYCODE_MENU: showSoftInput.showSoftInput(mapView, 0); break; case KeyEvent.KEYCODE_1: //zoom in mc.zoomIn(); break; case KeyEvent.KEYCODE_2: //zoom out mc.zoomOut(); break; case KeyEvent.KEYCODE_4: // scroll left mc.scrollBy(-4, 0); break; case KeyEvent.KEYCODE_5: // scroll right mc.scrollBy(4, 0); break; } return super.onKeyDown(keyCode, event); } what's wrong? Idan.
add this to the first line: InputMethodManager showSoftInput=(InputMethodManager)this.getSystemService(Context.INPUT_METHOD_SERVICE);
oh my eyes... Please don't add that much code in comments. Edit your original question to add that code. Also, long menu button press should always cause the soft keyboard to display. If it's causing your app to crash then provide the stack trace... in your original question.
Ohh, i am sorry for that, ill note it for next time(about the code adding). about what u said with the long menu press.. ive tried it.. and it just didnt work.. the crush wwas with something else. and now it's fixed. but if i just press long menu.. it doesnt show up.. not in emulator, and not on real phone. ive tried it while i`am on mapview activity. why it doesnt show up? Thanks, Idan.
2

Ive tried two options, but none of them worked in the emulator, as i said, i am trying to pop up soft keyboard on long-press menu:

@Override public boolean onKeyLongPress(int keyCode, KeyEvent event) { if (keyCode == KeyEvent.KEYCODE_MENU) { showSoftInput.getInputMethodList(); showSoftInput.toggleSoftInput(showSoftInput.SHOW_FORCED, 0); return true; } return super.onKeyLongPress(keyCode, event); } 

second option:

View.OnLongClickListener mLongClickListener = new View.OnLongClickListener() { @Override public boolean onLongClick(View v) { Configuration config = RouteMapActivity.this.getResources() .getConfiguration(); if (config.hardKeyboardHidden == Configuration.HARDKEYBOARDHIDDEN_YES) { InputMethodManager imm = (InputMethodManager) RouteMapActivity.this .getSystemService(Context.INPUT_METHOD_SERVICE); imm.showSoftInput(mapView, InputMethodManager.SHOW_IMPLICIT); // .SHOW_FORCED); } return false; } }; 

Comments

0

You can do this from your`s AndroidManifest.xml by adding

<activity android:windowSoftInputMode="stateVisible" ... > ... </activity> 

But note: If the user's device has an attached hardware keyboard, the soft input method does not appear. http://developer.android.com/training/keyboard-input/visibility.html

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.