如何从EditText OnClickListener动态选择文本?
问题描述:
我想在OnClickListener上使用android select文本功能,而不是onlongclicklistener.有什么办法吗?有人可以帮我吗?谢谢
I want to use the android select text functionality on OnClickListener rather than onlongclicklistener. Is there any way to do this? Can anybody help me regarding this? Thanks
答
android:selectAllOnFocus="true"
带代码(选项1):
yourEditText.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//((EditText)v).selectAll();
((EditText)v).setSelection(startValue, stopValue);
}
});
带代码(选项2):
yourEditText.setOnFocusChangedListener(new OnFocusChangedListener(){
@Override
public void onFocusChange(View v, boolean hasFocus){
if (hasFocus){
//((EditText)v).selectAll();
((EditText)v).setSelection(startValue, stopValue);
}
}
});