Setting onClickListener to editText

六眼飞鱼酱① 提交于 2019-12-08 05:09:24

问题


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);

回答1:


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
    }
});


来源:https://stackoverflow.com/questions/38694423/setting-onclicklistener-to-edittext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!