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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值