title: Bind Android textview to firebase database field
body: <p>I have a textView in my activity - say, "Username". It is supposed to be populated from a Firebase database.  I am making the Firebase query in Asynctask so as not to block the activity. However that means that the TextView loads first, before the Firebase query is completely executed.</p>
  
  <p>So what is the best way to refresh this textBox after the Firebase query is executed inside the AsyncTask and the username gets known?
  I do not want to showprogressBar and block the activity while the data is being fetched from the database. That would defeat the purpose of doing it in AsyncTask.</p>
  
  <p>Code for the AsyncTask is below</p>
  
  <pre><code>   private class CheckUserLoginAndRetrieveDataFromFirebase extends AsyncTask &lt;Void, Void, Void&gt; {
      @Override
      protected void onPreExecute() {
          super.onPreExecute();
      }
  
  
      @Override
      protected Void doInBackground(Void... voids) {
          if (thisAppUser!=null) {
              setUserDataForToday();  
              if (createNewNode) { //This is the first time the User is logging in
                  createUsersNodesForFirstTime();
              }
          }
          return null;
      }
  </code></pre>
  
  <p>Code for my Firebase Query in the AsyncTask is below</p>
  
  <pre><code>public static void setUserDataForToday() {
      setProperDatabaseReference(); //This sets reference to user specific nodes in the database
      myRef.child("dashboard").addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              Dashboard dashboard = dataSnapshot.getValue(Dashboard.class);
              if (dataSnapshot.getChildrenCount() &gt; 0) {
                  createNewNode = false;
                  if (dashboard.checkIfTodaysDateExistsInDatabase()) {
                      //An entry for todays date exists in database, so no data change needed
                      myDashboard = dashboard;
                  } 
  </code></pre>