在處理註冊表單的函數中,我想將按鈕的可見性設置爲不可見,並將進度條的可見性設置爲可見。現在的問題是,處理一些OAuth請求的以下代碼似乎可以防止這些小部件在我想要的位置顯示其可見性。在setVisibility()之後等待,直到窗口小部件在應用中真實可見
直到oauth請求完成,設置進度條的可見性會停止(凍結?)。我該如何解決這個問題?我覺得跟sleep()
S,wait()
S或定時器工作會在這裏一個壞的解決方案......
private void registerOnce(){
ProgressBar spinner = (ProgressBar) findViewById(R.id.progressBar);
Button login = (Button) findViewById(R.id.buttonLogin);
spinner.setVisibility(View.VISIBLE);
login.setVisibility(View.INVISIBLE);
// Here goes the code for some oauth requests
// This code here seems to prevent setting the
// the visibility where I want it to.
spinner.setVisibility(View.INVISIBLE);
login.setVisibility(View.VISIBLE);
}
如果你的[R egistration方法可能在另一個線程中執行,您應該將'view.setVisibility()'方法的調用與主應用程序線程同步,但這是一個猜測 – wjeshak