1

プログレスバースピナーに問題があります。

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

これは、ユーザーがログインをクリックしたときに実行されます。スピンはグローバルプログレスバー変数です。以下は、スピナーを処理するために使用される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に設定される前に表示される時間がないことは確かです。

4

1 に答える 1

0

AsyncTaskを作成する前にスピナーを表示に設定し、onPostExecuteで非表示にする必要があります。

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

myAsyncTask:

protected void onPostExecute(ProgressBar Spinner) {
    Spinner.setVisibility(View.GONE);
}
于 2012-03-19T19:38:20.660 に答える