I want to open the soft key pad when we click on or focus on edit text.Suppose in my application I have one Edittext view and image view at that time when i click on image view automatically the soft key pad will be closed.when i click on or focus on edittext at that time only Soft keypad will be opened what can i do? give me some suggestions.Thanks in advance
2 Answers
I guess what you're looking for is this: Close/hide the Android Soft Keyboard:
You can force Android to hide the virtual keyboard using the InputMethodManager, calling hideSoftInputFromWindow, passing in the token of the window containing your edit field.
InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE); imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
This will force the keyboard to be hidden in all situations. In some cases you will want to pass in InputMethodManager.HIDE_IMPLICIT_ONLY as the second parameter to ensure you only hide the keyboard when the user didn't explicitly force it to appear (by holding down menu).
Please search before you post your question.

- 1
- 1

- 4,077
- 4
- 32
- 40
The method described in the link mentioned in previous post (where I cannot post this answer because the thread is protected - interesting feature) works, but the answer does not specify WHERE (or WHEN) to execute the mentioned method.
I have had a problem with soft keyboard staying open and visible even when I show completely different view (by calling Activity.SetContentView(otherView)
. Also, I wanted the keyboard to disappear if a user opens a menu - in general, I wanted the input keyboard really GONE!!! unless user is actively using it (as should be).
The solution I found was overriding the onWindowVisibilityChanged and OnWindowsFocusChanged method of a view that contains the EditText:
public class MyView extends LinearLayout {
EditText myEditText;
@Override
protected void onFinishInflate() {
myEditText = (EditText)findViewById(R.id.EditText01);
//...
super.onFinishInflate();
}
@Override
protected void onWindowVisibilityChanged(int visibility) {
InputMethodManager imm = (InputMethodManager)_activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
super.onWindowVisibilityChanged(visibility);
}
@Override
public void onWindowFocusChanged(boolean hasWindowFocus) {
if(!hasWindowFocus) {
InputMethodManager imm = (InputMethodManager)_activity.getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
}
super.onWindowFocusChanged(hasWindowFocus);
}
// ...
}
Overriding both will hide the input keyboard in 'most cases'. I still had to repeat the above two lines when implementing the onEditorAction of the EditText callback interface.
Overriding only one of the two methods will make behavior a bit different, test and choose what you want to do.