[英]Display error text only for a specific amount of time?
How can I display a setError() only for specific amount of time? 如何仅在特定时间内显示setError()?
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. 使用OnCreate方法中的Handler可以使Non ui线程保留对UI线程的引用,因为一旦创建Thread,我们就会删除Ui线程。以前的帖子。 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();
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.