开发者

android edittext

开发者 https://www.devze.com 2023-01-16 09:33 出处:网络
I have one edittext EditText et1=(EditText)findViewById(R.id.EditText01); when i want to clear edittext i use et1.setText(\"\");

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开发者_StackOverflow 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));


Well, if you know what you want to clear you can get the text from the edittext and then remove the amount of characters from the end using 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());
}
0

精彩评论

暂无评论...
验证码 换一张
取 消