title: Wait until firebase data retrieves data
body: <p>i create quiz app and i using Firebase Realtime Database for retrieving data for my Android application. In my activity I retrieve all data for my questtion,answer,and choice.. but i waiting 4 - 5 sec until question show up.</p>
  
  <p>I want to show a progress bar as long as the data is not completely retrieved from the database. How do I check if all data is completely retrieved so that I can close the progress bar after the data is loaded?</p>
  
  <p>this is mainActivity.class</p>
  
  <pre><code>public class MainActivity extends AppCompatActivity {
  
  
  private TextView mScoreView;
  private TextView mQuestion;
  
  private Button mButtonChoice1, mButtonChoice2, mButtonChoice3, mButtonChoice4;
  
  public int mScore = 0;
  private int mQuestionNumber = 0;
  private String mAnswer;
  
  public static String alertTitle;
  
  private Firebase mQuestionRef, mchoice1Ref, mChoice2Ref, mChoice3Ref, mChoice4Ref, mAnswerRef;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_main);
  
  
  
  
      mScoreView = (TextView)findViewById(R.id.score);
      mQuestion = (TextView)findViewById(R.id.question);
  
      mButtonChoice1 = (Button)findViewById(R.id.choice1);
      mButtonChoice2 = (Button)findViewById(R.id.choice2);
      mButtonChoice3 = (Button)findViewById(R.id.choice3);
      mButtonChoice4 = (Button)findViewById(R.id.choice4);
  
      updateQuestion();
  
      //button1
      mButtonChoice1.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              if(mButtonChoice1.getText().equals(mAnswer)){
                  mScore = mScore + 1;
                  updateScore(mScore);
                  updateQuestion();
                  alertTitle = "Correct!";
                  corectanswer();
              }else {
                  updateQuestion();
                  wrong();
                  alertTitle = "Wrong!";
                  wronganswer();
              }
          }
      });
      //button1
  
      //button2
      mButtonChoice2.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              if(mButtonChoice2.getText().equals(mAnswer)){
                  mScore = mScore + 1;
                  updateScore(mScore);
                  updateQuestion();
                  alertTitle = "Correct!";
                  corectanswer();
              }else {
                  updateQuestion();
                  wrong();
                  alertTitle = "Wrong!";
                  wronganswer();
              }
          }
      });
      //button2
  
      //button3
      mButtonChoice3.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              if(mButtonChoice3.getText().equals(mAnswer)){
                  mScore = mScore + 1;
                  updateScore(mScore);
                  updateQuestion();
                  alertTitle = "Correct!";
                  corectanswer();
              }else {
                  updateQuestion();
                  wrong();
                  alertTitle = "Wrong!";
                  wronganswer();
              }
          }
      });
      //button3
  
      //button4
      mButtonChoice4.setOnClickListener(new View.OnClickListener() {
          @Override
          public void onClick(View view) {
              if(mButtonChoice4.getText().equals(mAnswer)){
                  mScore = mScore + 1;
                  updateScore(mScore);
                  updateQuestion();
                  alertTitle = "Correct!";
                  corectanswer();
  
              }else {
                  updateQuestion();
                  wrong();
                  alertTitle = "Wrong!";
                  wronganswer();
              }
          }
      });
      //button4
  
  }
  
  private void wrong(){
  
      //Toast.makeText(MainActivity.this, "Wrong", Toast.LENGTH_SHORT).show();
  }
  
  
  
  
  private void updateScore(int score){
      mScoreView.setText("" + mScore);
  }
  
  
  
  private void updateQuestion() {
      mQuestionRef = new Firebase("https://maths-quiz-d33d7.firebaseio.com/" + mQuestionNumber + "/question");
      mQuestionRef.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              String question = dataSnapshot.getValue(String.class);
              mQuestion.setText(question);
          }
  
          @Override
          public void onCancelled(FirebaseError firebaseError) {
  
          }
      });
  
  
      mchoice1Ref = new Firebase("https://maths-quiz-d33d7.firebaseio.com/" + mQuestionNumber + "/choice1");
      mchoice1Ref.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              String choice = dataSnapshot.getValue(String.class);
              mButtonChoice1.setText(choice);
          }
  
          @Override
          public void onCancelled(FirebaseError firebaseError) {
  
          }
      });
  
      mChoice2Ref = new Firebase("https://maths-quiz-d33d7.firebaseio.com/" + mQuestionNumber + "/choice2");
      mChoice2Ref.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              String choice = dataSnapshot.getValue(String.class);
              mButtonChoice2.setText(choice);
          }
  
          @Override
          public void onCancelled(FirebaseError firebaseError) {
  
          }
      });
  
      mChoice3Ref = new Firebase("https://maths-quiz-d33d7.firebaseio.com/" + mQuestionNumber + "/choice3");
      mChoice3Ref.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              String choice = dataSnapshot.getValue(String.class);
              mButtonChoice3.setText(choice);
          }
  
          @Override
          public void onCancelled(FirebaseError firebaseError) {
  
          }
      });
  
      mChoice4Ref = new Firebase("https://maths-quiz-d33d7.firebaseio.com/" + mQuestionNumber + "/choice4");
      mChoice4Ref.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              String choice = dataSnapshot.getValue(String.class);
              mButtonChoice4.setText(choice);
          }
  
          @Override
          public void onCancelled(FirebaseError firebaseError) {
  
          }
      });
      mAnswerRef = new Firebase("https://maths-quiz-d33d7.firebaseio.com/" + mQuestionNumber + "/answer");
      mAnswerRef.addValueEventListener(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              mAnswer = dataSnapshot.getValue(String.class);
          }
  
          @Override
          public void onCancelled(FirebaseError firebaseError) {
  
          }
      });
  
      if(mQuestionNumber == 4){
          corectanswer();
          wronganswer();
          Intent intent = new Intent(MainActivity.this,FinishActivity.class);
          intent.putExtra("RIGHT_ANSWER_COUNT", mScore);
          startActivity(intent);
      }else {
          mQuestionNumber++;
      }
  
  }
  
  public void corectanswer(){
      new AlertDialog.Builder(MainActivity.this)
              .setTitle(alertTitle)
              .setMessage(mAnswer)
              .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int i) {
                      dialog.cancel();
                  }
              }).show();
  }
  
  public void wronganswer(){
      new AlertDialog.Builder(MainActivity.this)
              .setTitle(alertTitle)
              .setMessage(mAnswer)
              .setPositiveButton("Ok", new DialogInterface.OnClickListener() {
                  @Override
                  public void onClick(DialogInterface dialog, int i) {
                      dialog.cancel();
                  }
              }).show();
  }
  </code></pre>
  
  <p>}</p>
  
  <p>and this startactivity.class</p>
  
  <pre><code>import com.google.firebase.database.FirebaseDatabase;
  
  public class StartActivity extends AppCompatActivity {
  
  private Button mulai;
  
  @Override
  protected void onCreate(Bundle savedInstanceState) {
      super.onCreate(savedInstanceState);
      setContentView(R.layout.activity_start);
  
  
          TextView label = (TextView)findViewById(R.id.quizmudah);
          label.setText("proooo");
  
          mulai = (Button)findViewById(R.id.mulai);
          mulai.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View v) {
                  Intent intent = new `Intent(getApplicationContext(),MainActivity.class);`
                  startActivity(intent);
              }
          });
    }
  }
  </code></pre>
  
  <p>this is mathQuiz.class activity</p>
  
  <pre><code>package com.belajardatabase.www.bikinquiz3;
  
  import android.app.Application;
  
  import com.firebase.client.Firebase;
  
  /**
   * Created by Iman on 7/3/2018.
   */
  
  public class MathsQuiz extends Application {
      @Override
      public void onCreate() {
          super.onCreate();
  
          Firebase.setAndroidContext(this);
      }
  }
  </code></pre>