简体   繁体   中英

clear the contents of the editText when long press on Back Space Key

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??

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);

}

Try this

@Override 
public boolean onKeyLongPress(int keyCode, KeyEvent event) {
  if (keyCode == KeyEvent.KEYCODE_DEL) 
  { 
    textView.setText("");
    return true; 
  } 
return super.onKeyLongPress(keyCode, event);

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM