简体   繁体   English

当单击按钮时,在连接WiFi时,在Android上显示进度对话框

[英]when click button, while connected wifi, show progress dialog on android

recently, When clicking the button WI-FI connect. 最近,当单击WI-FI连接按钮时。

but I want during connecting , showing progress dialog 但是我想在连接过程中显示进度对话框

How can I do ? 我能怎么做 ?

protected final ScanResult mScanResult;
 private OnClickListener mConnectOnClick = new OnClickListener() {
 @Override
    public void onClick(View v) {
 final WifiConfiguration config = Wifi.getWifiConfiguration(mWifiManager, mScanResult, mScanResultSecurity);
        boolean connResult = false;

if (config != null) {
       connResult = Wifi.connectToConfiguredNetwork(mFloating, mWifiManager, config, false);
    // I Think this part progress dialog. 
 }
        if (!connResult) {
            Toast.makeText(mFloating, R.string.toastFailed, Toast.LENGTH_LONG).show();
        }

        mFloating.finish();

if finish connect wifi, I want stop progress dialog 如果完成连接wifi,我要停止进度对话框
thanks. 谢谢。

For this you can use async task 为此,您可以使用异步任务

 class WIFIConfigurationTask extends AsyncTask<String, Void, Boolean> {
            ProgressDialog dialog;
           protected final ScanResult mScanResult;



            @Override
            protected void onPreExecute() {
                super.onPreExecute();
                dialog = new ProgressDialog(Your_Activity.this);
                dialog.setCancelable(false);
                dialog.setProgressStyle(android.R.style.Widget_ProgressBar_Small);
                dialog.setMessage(Constant.KEY_PLEASE_WAIT);
                dialog.show();
            }




            @Override
            protected Boolean doInBackground(String... params) {
               //Background Task
            }

            @Override
            protected void onPostExecute(Boolean response) {
                try {
                    super.onPostExecute(response);
                    if (isCancelled())
                        return;

                    dialog.dismiss();
     private OnClickListener mConnectOnClick = new OnClickListener() {
 @Override
    public void onClick(View v) {
 final WifiConfiguration config = Wifi.getWifiConfiguration(mWifiManager, mScanResult, mScanResultSecurity);
        boolean connResult = false;

if (config != null) {
       connResult = Wifi.connectToConfiguredNetwork(mFloating, mWifiManager, config, false);
    // I Think this part progress dialog. 
 }
        if (!connResult) {
            Toast.makeText(mFloating, R.string.toastFailed, Toast.LENGTH_LONG).show();
        }

        mFloating.finish();
                   }
        }

May it work.(Not Tested) 可以。(未测试)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 当我单击该按钮时我有一个按钮,我只想显示进度对话框2秒钟,如何在2秒钟后关闭进度对话框 - I have button when I click on that button I want to show progress dialog only for 2 seconds, how to dismiss progress dialog after 2 seconds Android在等待位置时显示进度对话框 - Android show progress dialog while waiting for location Android - 在 AsyncTask 执行时显示进度对话框 - Android - Show progress dialog while AsyncTask executes 当我打开我的android app且没有WiFi连接时,它显示没有WiFi连接,如代码中所给 - when i open my android app when no WiFi connected it show no WiFi connected as i given in the code 如何在Android中单击警报对话框的按钮时启动进度对话框? - How to start progress dialog on button click of alert dialog in android? 异步任务不显示按钮单击事件的进度对话框 - Asynchronous task not show Progress Dialog on click event of button wifi连接时如何进行对话框 - How to progress dialog while wifi connect 可运行的带有进度对话框的Android Show对话框完成 - Android Show dialog when Runnable with Progress Dialog finishes Android-仅在AsyncTask未完成的情况下,单击按钮上的“显示进度对话框” - Android - Display Progress Dialog on button click ONLY if AsyncTask has not completed 单击操作栏菜单项时无法显示“进度”对话框 - Unable to show Progress dialog when actionbar menu item click
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM