我有需要,我不得不自動關閉警報對話框中2種不同的情況下自動關閉警報對話框
- 自動關閉對話框後,我得到它我在等待
- 自動返回值 - 在用戶沒有輸入10秒後關閉對話框。我知道我應該使用某種計時器,但不知道如何將它與對話框連接起來。
我知道並理解它不正確的方式來處理用戶界面,但我的要求需要我這樣做。
請分享你的想法,
感謝,
SKU
我有需要,我不得不自動關閉警報對話框中2種不同的情況下自動關閉警報對話框
我知道並理解它不正確的方式來處理用戶界面,但我的要求需要我這樣做。
請分享你的想法,
感謝,
SKU
1-對於第一種情況:
AlertDialog alertDialog = new AlertDialog.Builder(Main.this).create();
...
alertDialog.show();
int valueIamWaitingFor = 5;
if (aValue == valueIamWaitingFor){
alertDialog.hide();
}
2-對於第二種情況:
private static final ScheduledExecutorService executor =
Executors.newSingleThreadScheduledExecutor();
public AlertDialog alertDialog = new AlertDialog.Builder(Main.this).create();
...
alertDialog.show();
Runnable hideDialog= new Runnable() {
public void run() {
this.alertDialog.hide();
}
};
executor.schedule(hideDialog, 10, TimeUnit.SECONDS);
嗨扎卡里亞......我跟着你與案例2做了什麼。但WRT的情況1,我正在等待返回值的字符串,這將大多數最少4秒(從一個單獨的線程)到最大8秒返回。我不確定您的案例1的代碼片段是否可以使用?你能解釋一下那部分嗎? – sku 2012-02-22 03:19:22
@sku:出於好奇,是什麼讓你確定該值會在8秒內返回最大值? – Zakaria 2012-02-22 08:02:07
它只是因爲長時間的觀察,如果它沒有在8秒內回答答案......有什麼問題。 – sku 2012-02-22 21:36:56