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

点点圈 提交于 2020-01-07 05:12:08

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!