6

I have a SherlockFragmentActivity and a SherlockFragment that is within a TabManager. In this Fragment I have RadioButtons, CheckBoxes, a Button and an EditText in a LinearLayout. The keyboard sometimes does not respond when pressing on the EditText.

In a 2.1 AVD the keyboard responds inconsistently, in a 4.0 AVD the keyboard does not respond at all, and on a device the keyboard responds inconsistently. Sometimes pressing the other objects then activates the ability to show the keyboard.

Here is the XML for the EditText:

    <EditText       android:id="@+id/EditText1"
                    android:layout_width="100dp"
                    android:layout_height="wrap_content"
                    android:inputType="number"
                    android:text="20" >

I'm confused of the inconsistent activity more so than the fact that it doesn't work on the 4.0 AVD. Any suggestions to why this is happening or a way to show the keyboard would be great.

piz
  • 83
  • 1
  • 4
  • 1
    Good to know it's an issue for more than just myself. I thought my programming was shitty. Sure wish I could find reference in the documentation for direct instructions for what to do since it becomes difficult to test other versions knowing there is the potential of finding bugs only within the emulator. – JRomero Nov 09 '12 at 13:40
  • I'm having this issue right now! I've got reports on my production app that the soft-keyboard isn't opening. I can't replicate it on ANYTHING I try, but I know the issue exists because a user SHOWED me. – AutoM8R Aug 20 '13 at 23:28

1 Answers1

7

You can register a focus listener for your edittext and open soft keyboard when it get focus:

edit_Text.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
    if(hasFocus){
        ((InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE))
.showSoftInput(edit_Text, InputMethodManager.SHOW_FORCED);
    }else
        Toast.makeText(getApplicationContext(), "lost the focus", 2000).show();
}
});

Edit:
For emulator,I think that it is not guaranteed.Really I did not any way to appear soft keyboard programmatically.Some times it appears and some times not.In emulator with android 4.0.3,you can see a symbol in notification bar instead of appearing soft keyboard:
enter image description here

Look at:
Event for Handling the Focus of the EditText
Forcing the Soft Keyboard open

Community
  • 1
  • 1
hasanghaforian
  • 13,858
  • 11
  • 76
  • 167
  • Thanks a lot. It works on my device consistently now. Although the 4.0 AVD still doesn't launch the keyboard. I'm going to try it on a device with ICS and let you know if it is still working properly. – piz Jun 16 '12 at 18:43