How can I display a setError() only for specific amount of time?
if(editText.getText().length()==0)
editText.setError("please input text");
Can I make it disappear after some seconds?
考虑使用敬酒通知 。
Try this:
Use Handler, in the OnCreate method, to keep a reference back to the UI thread from Non ui thread, because as soon as we create a Thread, we get dropped of the Ui thread.. sorry for the inconvenience for the left out line in the previous post. Now it will work as u wanted
Handler h;
onCreate(......) {
h = new Handler();
....
....
}
if(editText.getText().length()==0) {
editText.setError("please input text");
new Thread (new Runnable() {
public void run(){
try{
Thread.sleep(1000);
h.post(new Runnable() {
editText.setText(""); // this will put the non-ui work on the ui thread back
}
}catch(Exception ex){}
}
}.start();
}
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.