Search code examples
androidandroid-edittextsoft-keyboard

Setting onClickListener to editText


Hi im trying to add on click listener to editText so i can disable the softkeyboard when user clicks on edittext using this code below, how to do that?

InputMethodManager imm = (InputMethodManager)getSystemService(Context.INPUT_METHOD_SERVICE);
imm.hideSoftInputFromWindow(edittext.getWindowToken(), 0);

Solution

  • First it needs to be focusable...

    <EditText
        ...
        android:inputType="none"
        android:focusable="false"
        ... />
    

    You have to implement it in your code and than just add this to get an click listener...

    myEditText.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            // hide the keyboard
            // show own keyboard or buttons
        }
    });