Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 558
piz Avatar asked Jun 14 '12 02:06

piz


1 Answers

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

like image 152
hasanghaforian Avatar answered Nov 15 '22 03:11

hasanghaforian