2012-03-19 105 views
0

我有一个进度微调的一个问题:进度微调不显示

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."); 
} 

当用户点击登录该被执行。自旋是一个全局的progressbar变量。以下是用于处理微调器的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之前,微调没有时间显示。

+0

显示所有你的代码。微调不能既是阵列又是微调。 – Snicolas 2012-03-19 19:16:58

+0

我很好奇你为什么使用AsyncTask来管理UI。 – 2012-03-19 19:17:14

+1

我真的不明白这一点,你应该在调用你的AsyncTask并将它隐藏在onPostExecute中之前显示微调器,我不确定你的问题是微调器应该完全从View.GONE中移除 – bbedward 2012-03-19 19:20:45

回答

0

您需要创建的AsyncTask之前,你的微调器设置为可见的,它藏在onPostExecute,是这样的:

mySpinner.setVisibility(View.VISIBLE); 
myAsyncTask.Execute(); // etc, etc 

myAsyncTask:

protected void onPostExecute(ProgressBar Spinner) { 
    Spinner.setVisibility(View.GONE); 
}