我有一个 EditText:
EditText et1=(EditText)findViewById(R.id.EditText01);
当我想要清空 EditText 时,我使用 et1.setText("");
但是如果我需要从最后一个字符开始逐个删除,我没有解决方案,请问您能给我一个解决方案吗?
我有一个 EditText:
EditText et1=(EditText)findViewById(R.id.EditText01);
当我想要清空 EditText 时,我使用 et1.setText("");
但是如果我需要从最后一个字符开始逐个删除,我没有解决方案,请问您能给我一个解决方案吗?
Do you know about SubString?
String contents = et1.getText().toString();
et1.setText(contents.substring(0, contents.length()-2));
如果你知道你想要清除的内容,你可以从EditText中获取文本,然后使用string.substring(0,numOfEND)从末尾删除指定数量的字符。
if (et1.getSelectionStart() > 0) { //check that you are not deleting from the zero point
et1.getText().delete(et1.getSelectionStart()-1, et1.getSelectionEnd());
}