【发布时间】:2016-10-02 23:10:57
【问题描述】:
我正在尝试使用处理程序来等待我的 wifi 连接。这是我正在使用的代码:
final AlertDialog alertDialog2 = new AlertDialog.Builder(new android.view.ContextThemeWrapper(context, R.style.AlertDialogCustom)).create();
alertDialog2.setTitle("Loading...");
alertDialog2.setIcon(R.drawable.check);
alertDialog2.show();
Handler handler = new Handler();
int count = 0;
while (!isConnected() /*Check wifi connection*/) {
handler.postDelayed(new Runnable() {
@Override
public void run() {
alertDialog2.dismiss();
// do other thing
}
}, 200);
count++;
/*stop the loop after 20s*/
if (count > 100) {
break;
}
}
正如您在这段代码中看到的那样,我想在操作期间显示一个正在加载的 alertDialog,当它完成时我想停止它以通知用户他的 wifi 连接。
【问题讨论】: