I have one edittext EditText et1=(EditText)findViewById(R.id.EditText01);
when i want to clear edittext i use et1.setText(""); but if i have to clear edittext one by one character from the last for this i have no solution can u pls give me solution
Do you know about SubString?
String contents = et1.getText().toString();
et1.setText(contents.substring(0, contents.length()-2));
好吧,如果您知道要清除的内容,可以从edittext中获取文本,然后使用string.substring(0,numOfEND)从末尾删除字符数量;
If your editText has focus, then you can delete characters backspacing from the cursor like this:
if (et1.getSelectionStart() > 0) { //check that you are not deleting from the zero point
et1.getText().delete(et1.getSelectionStart()-1, et1.getSelectionEnd());
}
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.