How to use getSelectionStart and getSelectionEnd o

2019-08-19 06:00发布

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条回答
家丑人穷心不美
2楼-- · 2019-08-19 06:10

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;          
        }
    } 
查看更多
登录 后发表回答