[英]Display error text only for a specific amount of time?
如何僅在特定時間內顯示setError()?
if(editText.getText().length()==0)
editText.setError("please input text");
幾秒鍾后我可以使其消失嗎?
考慮使用敬酒通知 。
嘗試這個:
使用OnCreate方法中的Handler可以使Non ui線程保留對UI線程的引用,因為一旦創建Thread,我們就會刪除Ui線程。以前的帖子。 現在它將按您的意願工作
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.