Search code examples
androidandroid-layoutandroid-edittext

Soft keyboard doesn't appear


I'm testing my app on android 4.0.4 Samsung galaxy duos, the problem is if I set:

android:textIsSelectable="true"

the keyboard doesn't appear, though it appears on the emulator. Any suggestions?

Here is how my EditBox looks like

<EditText 

        android:focusable="true"
        android:layout_width="fill_parent" 
        android:layout_height="wrap_content"        
        android:inputType="textVisiblePassword|textCapWords|textMultiLine"
        android:textIsSelectable="true"
        android:gravity="top|left"
        android:minLines="6"
        android:maxLines="10"
        android:minHeight="140dp"
        android:hint="@string/message"
        />
      <requestFocus />

Solution

  • Add a requestfocus. In xml:

    <EditText>
        <requestFocus />
    </EditText>  
    

    Programmatically

    edittext.requestFocus();
    

    To "force" the SoftKeyboard to appear, you can do it dynamically:

    InputMethodManager mImm = (InputMethodManager) 
                            getSystemService(Context.INPUT_METHOD_SERVICE);  
    mImm.showSoftInput(SearchEdit, InputMethodManager.SHOW_IMPLICIT);  
    

    Set onFocusChangeListener to appear your keyboard:

    edittext.setFocusable(true);  
    edittext.setOnFocusChangeListener(new View.OnFocusChangeListener() {  
       @Override  
       public void onFocusChange(View v, boolean hasFocus) {  
           if (hasFocus)   
               mImm.showSoftInput(SearchEdit, InputMethodManager.SHOW_IMPLICIT);  
           else  
               mImm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);  
       } 
    });  
    

    See InputMethodManager Documentation for more information.
    See also these answers to forcing the Keyboard to appear: Forcing the Soft Keyboard open