I want to clear the text in EditText
after it has been saved in database.
Here is my code:
pictureDescription.addTextChangedListener(new TextWatcher()
{
public void afterTextChanged(Editable textValue)
{
String content = textValue.toString();
db.updatePicDes(content,lastSnapId);
}
}
just use the android:hint attribute in your EditText. This text shows up when the box is empty and not focused, but disappears upon selecting the EditText box. this should be the accepted answer, +1 for simplicity.
Use editText. getText(). clear() . This is the correct way to do this.
Either setText("") or setText(null) — either one of those would work. I use setText(null) for readability reasons. If you are worried about readability, you can also add <string name="empty" /> to strings. xml and use textView.
editText.text.clear()
Alternatively, you can add a small extension function to make it even simpler.
editText.clear()
fun EditText.clear() {
text.clear()
}
Use editText.getText().clear()
.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With