How to use getSelectionStart and getSelectionEnd of EditText when user touches EditText?

被刻印的时光 ゝ 提交于 2019-12-12 06:17:49

问题


I want to know by using which method I can get whether the user selecting text in edittext or not so I can use getSelectionStart and getSelectionEnd to perform my desire task.


回答1:


You can check if your EditText widget has been focused (usually when user touches it on the screen).

findViewById(R.id.editText1).setOnFocusChangeListener(this);

and then implement the listener (in this case within the same class)

public void onFocusChange(View arg0, boolean arg1) {
        switch(arg0.getId()){
        case R.id.editText1:
            if(arg1){
                // has focus
            }
            else{
                // doesn't
            }
            break;          
        }
    } 


来源:https://stackoverflow.com/questions/6427380/how-to-use-getselectionstart-and-getselectionend-of-edittext-when-user-touches-e

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