In my android app, I have 3 EditTexts in my one activity. I created my own number pad in the activity. Whenever i tap any EditText, soft keyboard comes up. I want to block that permanently for this activity but if user tap an EditText then it should be in focus. Like a cursor blinking. Any idea how can i do that? Thanks in advance.
Asked
Active
Viewed 2,007 times
4
-
possible duplicate of [Close/hide the Android Soft Keyboard](http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard) – Seshu Vinay Sep 27 '13 at 08:39
-
its not duplicate of that question. When i click on the EditText second time, keyboard appears. I want to close it permanently and keep edittext in focus as well. So for your information its not duplicate. – Piscean Sep 27 '13 at 09:01
4 Answers
6
Hiding Keyboard Manually Here
InputMethodManager mgr = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
YourEditText.setOnFocusChangeListener(new OnFocusChangeListener() {
@Override
public void onFocusChange(View v, boolean hasFocus) {
// TODO Auto-generated method stub
mgr.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
});
YourEditText.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
// TODO Auto-generated method stub
mgr.hideSoftInputFromWindow(v.getWindowToken(), 0);
}
});

Software Sainath
- 1,040
- 2
- 14
- 39
0
i check my self. its working correct. InputMethodManager imm ;
edittext1 = (EditText) findViewById(R.id.editText1);
imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
edittext1.setOnClickListener(new OnClickListener() {
public void onClick(View v) {
imm.hideSoftInputFromWindow(edittext1.getWindowToken(), 0);
}
});

harikrishnan
- 1,985
- 4
- 32
- 63
-
strange because is really not working with my app. Everytime i tap on edittext, soft keyboard appears – Piscean Sep 30 '13 at 08:56
-
i check with my mobile samsung galax note 2 4.1, soft keyboard not appear.i will check some other – harikrishnan Sep 30 '13 at 10:07
-
I am checking it with Samsumg s3 and mototola Et1. soft keyboard is appearing in both – Piscean Sep 30 '13 at 12:20
-
try this link also.. http://stackoverflow.com/questions/1109022/close-hide-the-android-soft-keyboard?rq=1 – harikrishnan Oct 01 '13 at 05:09
0
In place of setting hideSoftInputFromWindow() to each EditText, it will be good if you set the parameter for the parent layout of the activity. Suppose the parent layout of the activity is a LinearLayout, Then,
linearLayout = (LinearLayout) findViewById(R.id.linearLayout);
/* Hide keyboard from this activity permanently */
InputMethodManager manager = (InputMethodManager) getSystemService(Context.INPUT_METHOD_SERVICE);
manager.hideSoftInputFromWindow(linearLayout.getWindowToken(),0);
Or You can also implement the same thing for xml
<EditText
android:focusable="false"
.../>
This disables the keyboard permanently for that edittext

code_lucidal58
- 1
- 3
0
Android studio suggested the following command that keeps the keyboard from showing up. I went ahead and threw it into a function as follows and called it for each EditText object.
private void hideKeyboard(EditText editText){
editText.setShowSoftInputOnFocus(false);
}

Mr. S
- 126
- 6