Hide Soft keyboard on return key press Hide Soft keyboard on return key press android android

Hide Soft keyboard on return key press


If you don't want multiple line, for you edittext you can just specify a single line. For the edittext and also you can put imeOptions as Done like this:

<EditText    android:id="@+id/edittext_done"   android:layout_width="fill_parent"   android:layout_height="wrap_content"   android:imeOptions="actionDone"   android:singleLine="true"   />

I clearly don't know, whether you are trying to achieve this or not.Any way take a look.

EDIT: android:singleLine is deprecated since API 3 due to bad performance, you have to use android:maxLines instead. singleLine will be available because even now some effects are not supported by android:maxLines attribute.


I solved the issue by changing the following in the XML file from:

 android:inputType="textMultiLine"

to:

 android:inputType="textImeMultiLine"


Below code works for me.

IN XML:

    android:imeOptions="actionDone"    android:inputType="textCapWords"

IN JAVA CLASS:

    edit_text.setOnEditorActionListener(new OnEditorActionListener() {                @Override                public boolean onEditorAction(TextView v, int actionId, KeyEvent event) {                    // TODO Auto-generated method stub                    if ((actionId==EditorInfo.IME_ACTION_DONE )   )                     {                           //Toast.makeText(getActivity(), "call",45).show();                       // hide virtual keyboard                       InputMethodManager imm = (InputMethodManager)getActivity().getSystemService(Context.INPUT_METHOD_SERVICE);                       //or try following:                       //InputMethodManager imm = (InputMethodManager)getBaseContext().getSystemService(Context.INPUT_METHOD_SERVICE);                       imm.hideSoftInputFromWindow(auto_data.getWindowToken(), 0);                       return true;                    }                    return false;                }            });