4

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.

Piscean
  • 3,010
  • 12
  • 43
  • 88
  • 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 Answers4

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,000
  • 2
  • 13
  • 37
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
  • 2,075
  • 3
  • 26
  • 60
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

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
  • 61
  • 5