0

I would like to off android default keyboard when i pressed at editText. Such that the default keyboard will not popup. I have tried folloing code but didn't worked:

   <?xml version="1.0" encoding="utf-8"?>
    <LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
        android:id="@+id/lltest"
        android:layout_width="fill_parent"
        android:layout_height="fill_parent"
        android:orientation="vertical" >
   <EditText
        android:id="@+id/editText0"
       android:layout_width="fill_parent"
      android:layout_height="wrap_content">
  </EditText>
 </LinearLayout>

And code is:

    edtEdit1.setOnTouchListener(new View.OnTouchListener() {

        @Override
        public boolean onTouch(View v, MotionEvent event) {
            // TODO Auto-generated method stub

InputMethodManager imm =                          (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
            imm.hideSoftInputFromWindow(edtEdit1.getWindowToken(), 1);
            return false;
        }
    });
Paresh Mayani
  • 122,920
  • 69
  • 234
  • 290

4 Answers4

2

Have you tried

 android:editable="false" 

in you xml declaration of edit text??

Sandip Jadhav
  • 7,187
  • 8
  • 40
  • 73
1

for hidden

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_HIDDEN);

for show

getWindow().setSoftInputMode(WindowManager.LayoutParams.SOFT_INPUT_STATE_ALWAYS_VISIBLE);
SuReSh PaTi
  • 1,345
  • 6
  • 28
  • 46
0

Try this

You put 1 instead of 0

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(myEditText.getWindowToken(), 0);
Newts
  • 1,346
  • 13
  • 23
-1

To prevent the Android keyboard from appearing when an EditText is touched, just return true in the onTouch() method.

edtEdit1.setOnTouchListener(new View.OnTouchListener() {

    @Override
    public boolean onTouch(View v, MotionEvent event) {
        return true;
    }
});
flawyte
  • 7,678
  • 4
  • 44
  • 63