How come the Android soft keyboard is not responding to EditText?

你。 提交于 2019-12-30 09:23:42

问题


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.


回答1:


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:

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



来源:https://stackoverflow.com/questions/11025927/how-come-the-android-soft-keyboard-is-not-responding-to-edittext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!