android – 在警告对话框中显示进度条

前端之家收集整理的这篇文章主要介绍了android – 在警告对话框中显示进度条前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我的应用程序中有一个用于登录身份验证的警告对话框.在发送请求时,我想显示一个进度条,如果响应是成功则想要解雇.如果有人知道,请帮助我.我使用下面的代码
final AlertDialog.Builder alert = new AlertDialog.Builder(this);
LinearLayout login = new LinearLayout(this);
TextView tvUserName = new TextView(this);
TextView tvPassword = new TextView(this);
TextView tvURL = new TextView(this);
final EditText etUserName = new EditText(this);
final EditText etPassword = new EditText(this);
final EditText etURL = new EditText(this);
login.setOrientation(1); // 1 is for vertical orientation
tvUserName.setText(getResources().getString(R.string.username));
tvPassword.setText(getResources().getString(R.string.password));
tvURL.setText("SiteURL");
login.addView(tvURL);
login.addView(etURL);
login.addView(tvUserName);
login.addView(etUserName);
login.addView(tvPassword);
etPassword.setInputType(InputType.TYPE_CLASS_TEXT
| InputType.TYPE_TEXT_VARIATION_PASSWORD);
login.addView(etPassword);
alert.setView(login);
alert.setTitle(getResources().getString(R.string.login));
alert.setCancelable(true);
alert.setPositiveButton(getResources().getString(R.string.login),new DialogInterface.OnClickListener() {
    public void onClick(final DialogInterface dialog,int whichButton) {
        strhwdXml = etURL.getText().toString();
        strUserName = etUserName.getText().toString();
        XmlUtil.username = strUserName;
        strPassword = etPassword.getText().toString();
        if ((strUserName.length() == 0)
        && (strPassword.length() == 0)
        && (strhwdXml.length() == 0)) {
            Toast.makeText(
            getBaseContext(),getResources().getString(
            R.string.userPassword),Toast.LENGTH_SHORT).show();
            onStart();
            } else {
            final SharedPreferences prefs = PreferenceManager
            .getDefaultSharedPreferences(getApplicationContext());
            SharedPreferences.Editor prefsEditor = prefs
            .edit();
            try {
                StringBuffer inStreamBuf = new StringBuffer();
                inStreamBuf = XmlUtil
                .getLoginAuthResponse(strUserName,strPassword,strhwdXml);
                strXmlResponse = inStreamBuf.toString();
                Log.e("Response:",strXmlResponse);
                String parsedXML = ParseResponse(strXmlResponse);
                if (parsedXML
                .equalsIgnoreCase(getResources()
                .getString(R.string.success))) {
                }

解决方法

使用它可能更容易
ProgressDialog dialog = ProgressDialog.show(MyActivity.this,"","Loading. Please wait...",true);

您可以阅读有关进度对话框here的更多信息

取消将是

dialog.dismiss();

This class was deprecated in API level 26. ProgressDialog is a modal dialog,which prevents the user from interacting with the app. Instead of using this class,you should use a progress indicator like ProgressBar,which can be embedded in your app’s UI. Alternatively,you can use a notification to inform the user of the task’s progress.For more details 07001

原文链接:https://www.f2er.com/android/314360.html

猜你在找的Android相关文章