我对进度条微调器有疑问:
ProgressBarSpinner spinner = new ProgressBarSpinner();
spinner.execute(Spin);
Login LoginUser = new Login();
if(LoginUser.LoginUser(UserNameValue.getText().toString(), PasswordValue.getText().toString())) {
MessageBox("Login information", "You've been successfully logged in, press OK to continue.");
Document XMLInfo = null;
Passphrase = PasswordValue.getText().toString();
try {
XMLInfo = XMLfromString(LoginUser.ProfileXML);
XML_ProfileParser(XMLInfo);
TickerString = FillProfileSlider(XMLInfo);
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
Spin.setVisibility(ProgressBar.GONE);
setContentView(R.layout.profile);
TextView ProfileTicker = (TextView)findViewById(R.id.ProfileTicker);
TextView UserInformation = (TextView)findViewById(R.id.NameInfo);
TextView MoneyLabel = (TextView)findViewById(R.id.MoneyInfo);
UserInformation.setText(ProfileInfo.get("FirstName") + " " + ProfileInfo.get("LastName"));
MoneyLabel.setText(ProfileInfo.get("Money") + " Kr");
if(Integer.parseInt(ProfileInfo.get("Messages")) >= 1) {
ImageView MessageImage = (ImageView)findViewById(R.id.MailImage);
MessageImage.setOnClickListener(ImageListener);
MessageImage.setVisibility(ImageView.VISIBLE);
}
ProfileTicker.setText(Html.fromHtml(TickerString));
}
else {
Spin.setVisibility(ProgressBar.GONE);
MessageBox("Login information", "The submitted login information seems to be invalid.");
}
这在用户单击登录时执行。Spin 是一个全局进度条变量。下面是用于处理微调器的 Async 类。
private class ProgressBarSpinner extends AsyncTask<ProgressBar, Integer, ProgressBar>
{
protected ProgressBar doInBackground(ProgressBar...Spinner) {
return Spinner[0];
}
protected void onProgressUpdate(Integer... progress) {
}
protected void onPostExecute(ProgressBar Spinner) {
Spinner.setVisibility(ProgressBar.VISIBLE);
Spinner.showContextMenu();
}
}
问题:如果我尝试写
Spin.setVisibility(ProgressBar.GONE);
登录授权后,微调器根本不会显示。但是,如果我删除 ProgressBar.Gone 部分,则会显示微调器。但是,如果该部分存在,则似乎应用程序在继续之前“挂起”(登录用户或显示错误消息,告知用户名或密码错误)。
问题可能是什么?
我确信登录没有那么快,以至于微调器在设置为 GONE 之前没有时间显示。