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);
}
}
使用editText.getText().clear()
。
Just set it to empty string. I think it should do it.
EditText editText = (EditText)findViewById(R.id.edit_text);
editText.setText("");
editText.text.clear()
Alternatively, you can add a small extension function to make it even simpler.
editText.clear()
fun EditText.clear() {
text.clear()
}
你可以使用EditText.setText("");
如果您不想在单击按钮时执行此操作,则最好在 FocusChangedListener 中执行此操作。
pictureDescription.addTextChangedListener(new TextWatcher() {
public void afterTextChanged(Editable textValue) {
String content = textValue.toString();
db.updatePicDes(content,lastSnapId);
pictureDescription.setText("");
}
}
String content = textValue.toString();
db.updatePicDes(content,lastSnapId);
editText.setText("");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.