How to clear the text in edittext

不打扰是莪最后的温柔 提交于 2019-12-22 03:21:04

问题


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

  }
}

回答1:


Use editText.getText().clear().




回答2:


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

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



回答3:


you can use EditText.setText("");




回答4:


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




回答5:


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



回答6:


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



回答7:


If using Kotlin, try:

editText.text.clear()


来源:https://stackoverflow.com/questions/7426443/how-to-clear-the-text-in-edittext

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!