问题
Because my editext is the string format it doesn't clear all the text when i long press on the backspace key. so i am looking for solution to clear all text when long press on the backspace key ??
回答1:
Try this
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_DEL)
{
textView.setText("");
return true;
}
return super.onKeyLongPress(keyCode, event);
回答2:
You can do it by overriding onKeyLongPress()
like
@Override
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
if (keyCode == KeyEvent.KEYCODE_BACK)
{
TextView myTextView = (TextView) findViewById(R.id.myTextView);
myTextView.setText("");
return true;
}
return super.onKeyLongPress(keyCode, event);
}
来源:https://stackoverflow.com/questions/45428633/clear-the-contents-of-the-edittext-when-long-press-on-back-space-key