Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to clear the text in edittext

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);

  }
}
like image 821
anny Avatar asked Sep 15 '11 05:09

anny


People also ask

How do I remove text from EditText?

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.

How do I delete text in EditText Kotlin?

Use editText. getText(). clear() . This is the correct way to do this.

How to clear textView in android Studio?

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.


2 Answers

If using Kotlin, try:

editText.text.clear()

Extension Solution

Alternatively, you can add a small extension function to make it even simpler.

editText.clear()

fun EditText.clear() {
    text.clear()
}
like image 177
Gibolt Avatar answered Sep 24 '22 02:09

Gibolt


Use editText.getText().clear().

like image 37
IgorGanapolsky Avatar answered Sep 22 '22 02:09

IgorGanapolsky