anny
anny

Reputation: 161

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

  }
}

Upvotes: 16

Views: 28494

Answers (7)

Gibolt
Gibolt

Reputation: 47127

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()
}

Upvotes: 11

bhargavkumar040
bhargavkumar040

Reputation: 800

String content = textValue.toString();
db.updatePicDes(content,lastSnapId);
editText.setText("");

Upvotes: 0

Via
Via

Reputation: 29

you can use EditText.setText("");

Upvotes: 2

IgorGanapolsky
IgorGanapolsky

Reputation: 26821

Use editText.getText().clear().

Upvotes: 32

Ron
Ron

Reputation: 24235

You better do that in FocusChangedListener if you donot want it on clicking a button.

Upvotes: 1

Tomzi
Tomzi

Reputation: 143

Just set it to empty string. I think it should do it.

EditText editText = (EditText)findViewById(R.id.edit_text);
editText.setText("");

Upvotes: 10

Balaji.K
Balaji.K

Reputation: 4829

pictureDescription.addTextChangedListener(new TextWatcher() {
   public void  afterTextChanged(Editable textValue) { 
          String content = textValue.toString(); 
          db.updatePicDes(content,lastSnapId);
           pictureDescription.setText("");
   }
}

Upvotes: 0

Related Questions