Is there a way to reset the edittext value without setting text like:
((EditText) findViewById(R.id.yoursXmlId)).setText("");
EDIT:
Textchanged listner is called when i use setText("").
Is there a way to reset the edittext value without setting text like:
((EditText) findViewById(R.id.yoursXmlId)).setText("");
EDIT:
Textchanged listner is called when i use setText("").
Another option is: EditText.getText().clear();
But you'll have to cast anyway:
((EditText) findViewById(R.id.yoursXmlId)).getText().clear();
EditText
again the initial text appears again –
Fairchild you can use following way
Kotlin:
myEditText.text.clear()
Java:
EditText myEditText = ((EditText) findViewById(R.id.yoursXmlId));
myEditText.getText().clear()
A function for that would be:
fun setTextViewEmpty(textView: TextView){
(textView as EditText ).text.clear() }
inspired by this
I had a case where a Samsung device was not blanking out text with setText(""), so I used:
String BLANK = "\u0020"; // space character
setText (BLANK);
and it worked this way. It may have been a font issue.
if anyone is finding the selected answer not working please try with
editText.post(() -> editText.getText().clear());
or
editText.post(new Runnable() {
@Override
public void run() {
editText.getText().clear();
}
});
© 2022 - 2024 — McMap. All rights reserved.