如何当用户触摸使用的EditText中的EditText和getSelectionStart getSelectionEnd? [英] How to use getSelectionStart and getSelectionEnd of EditText when user touches EditText?
本文介绍了如何当用户触摸使用的EditText中的EditText和getSelectionStart getSelectionEnd?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想用哪种方法来知道我能是否EditText上用户选择的文本或不那么我可以使用getSelectionStart和getSelectionEnd执行我的愿望任务。
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.
推荐答案
您可以检查,如果你的的EditText
部件都集中(通常当用户触摸在屏幕上) 。
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;
}
}
这篇关于如何当用户触摸使用的EditText中的EditText和getSelectionStart getSelectionEnd?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文