开发者

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

开发者 https://www.devze.com 2023-03-14 05:35 出处:网络
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 ge开发者_运维问答tSelectionEnd to perform my desire task.You can ch

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 ge开发者_运维问答tSelectionEnd to perform my desire task.


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

精彩评论

暂无评论...
验证码 换一张
取 消