Android 在处理程序后台事件中显示ProgressDialog

Android 在处理程序后台事件中显示ProgressDialog,android,android-alertdialog,android-progressbar,android-handler,Android,Android Alertdialog,Android Progressbar,Android Handler,我想用文本扫描显示消息10秒钟 在AsyncTask中使用onPreExecute时,通常会执行以下操作: AlertDialog.Builder dialogo1 = new AlertDialog.Builder(getApplicationContext()); dialogo1.setMessage("Scanning..."); dialogo1.setCancelable(false); 但是在使用处理程序时如何执行相同的操作,如下所示--- 因此,当扫

我想用文本扫描显示消息10秒钟

AsyncTask
中使用
onPreExecute
时,通常会执行以下操作:

AlertDialog.Builder dialogo1 = 
new AlertDialog.Builder(getApplicationContext()); 
dialogo1.setMessage("Scanning...");            
dialogo1.setCancelable(false);
但是在使用处理程序时如何执行相同的操作,如下所示---

因此,当扫描在后台进行10秒时,让我们提供一个对话框,直到扫描完成。

我想……也许吧

if (enable) {
     //show dialog box here
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
    mScanning = false;
    //dismiss dialog box here
    Log.d(TAG,getCtx() + "run stopLeScan");
    mBluetoothAdapter.stopLeScan(mLeScanCallback);
    }
}, SCAN_PERIOD);
Log.d(TAG,getCtx()+" scanLeDevice startLeScan:"+enable);
mBluetoothAdapter.startLeScan(mLeScanCallback);
} else {
Log.d(TAG,getCtx()+ " scanLeDevice stopLeScan:"+enable);
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
}

您可以像这样在处理程序中使用--


您希望实现什么查看?我希望时间处理程序的警报对话框正在对LE设备执行扫描,即扫描周期给定的10000毫秒时间。在handler中如何处理上述方法?
if (enable) {
     //show dialog box here
mHandler.postDelayed(new Runnable() {
@Override
public void run() {
    mScanning = false;
    //dismiss dialog box here
    Log.d(TAG,getCtx() + "run stopLeScan");
    mBluetoothAdapter.stopLeScan(mLeScanCallback);
    }
}, SCAN_PERIOD);
Log.d(TAG,getCtx()+" scanLeDevice startLeScan:"+enable);
mBluetoothAdapter.startLeScan(mLeScanCallback);
} else {
Log.d(TAG,getCtx()+ " scanLeDevice stopLeScan:"+enable);
mBluetoothAdapter.stopLeScan(mLeScanCallback);
}
}
ProgressDialog pDialog = new ProgressDialog(Context);
    pDialog.setTitle("Please Wait!");
    pDialog.setMessage("Scanning...");
    pDialog.show();

new Handler().postDelayed(new Runnable() {

        @Override
        public void run() {
            // TODO Auto-generated method stub
            pDialog.dismiss();
        }
    }, SCAN_PERIOD);