我想使用android选择文本功能上onclicklistener而不是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
使用XML:
android:selectAllOnFocus="true"
与code(选项1):
with code (option1):
yourEditText.setOnClickListener(new OnClickListener() {
@Override
public void onClick(View v) {
//((EditText)v).selectAll();
((EditText)v).setSelection(startValue, stopValue);
}
});
与code(选项2):
with code (option2):
yourEditText.setOnFocusChangedListener(new OnFocusChangedListener(){
@Override
public void onFocusChange(View v, boolean hasFocus){
if (hasFocus){
//((EditText)v).selectAll();
((EditText)v).setSelection(startValue, stopValue);
}
}
});