title: How to update a List view in real-time Firebase - Android
body: <p>I have been having some trouble updating my Friends list(mListView) view in real time in the application, it only seems to update when it is launched. I know its a matter of an update function but i do not know what to use. </p>
  
  <p>(I'm rather new to firebase and android, and i'm still learning about them.)</p>
  
  <p>Here is the code:</p>
  
  <pre><code>private ListView mListView;
  private ArrayList&lt;String&gt; mFriends;
  
  private List&lt;User&gt; mUserList;
  
  private UserListAdapter mAdapter;
  
  @Nullable
  @Override
  public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
      View view = inflater.inflate(R.layout.fragment_profile_friends, container, false);
      mSearchParam = (EditText) view.findViewById(R.id.searchFriends);
      mListView = (ListView) view.findViewById(R.id.lvProfileFriends);
      mPhotos = new ArrayList&lt;&gt;();
      mUserList = new ArrayList&lt;&gt;();
      mFriends = new ArrayList&lt;&gt;();
  
  
  
      DisplayFriends();
  
      return view;
  }
  
  private void DisplayFriends(){
      getFriends();
  }
  
  
  private void updateUsersList(){
      Log.d(TAG, "updateUsersList: updating users list");
  
      mAdapter = new UserListAdapter(getActivity(), R.layout.layout_user_listitem, mUserList);
  
      mListView.setAdapter(mAdapter);
  
      mListView.setOnItemClickListener(new AdapterView.OnItemClickListener() {
          @Override
          public void onItemClick(AdapterView&lt;?&gt; parent, View view, int position, long id) {
              Log.d(TAG, "onItemClick: selected user: " + mUserList.get(position).toString());
  
              //navigate to profile activity
              Intent intent = new Intent(getActivity(), ViewProfileFragment.class);
              intent.putExtra(getString(R.string.calling_activity), getString(R.string.fragment_profile));
              intent.putExtra(getString(R.string.intent_user), mUserList.get(position));
              startActivity(intent);
          }
      });
  }
  
  private void updateFriendsList(){
      Log.d(TAG, "getPhotos: getting Friend(s)");
      DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
      for(int i = 0; i &lt; mFriends.size(); i++){
          final int count = i;
          Query query = reference
                  .child(getString(R.string.dbname_users))
                  .orderByChild(getString(R.string.field_user_id))
                  .equalTo(mFriends.get(i));
          query.addListenerForSingleValueEvent(new ValueEventListener() {
              @Override
              public void onDataChange(DataSnapshot dataSnapshot) {
                  for(DataSnapshot singleSnapshot : dataSnapshot.getChildren()){
  
                      mUserList.add(singleSnapshot.getValue(User.class));
                  }
                  if(count &gt;= mFriends.size() - 1){
                      updateUsersList();
                  }
              }
  
              @Override
              public void onCancelled(DatabaseError databaseError) {
  
              }
          });
      }
  }
  
  
  private void getFriends(){
      Log.d(TAG, "getFollowing: searching for FRIENDS **************************************");
      mFriends.clear();
      mUserList.clear();
      DatabaseReference reference = FirebaseDatabase.getInstance().getReference();
      Query query = reference
              .child(getString(R.string.dbname_friends))
              .child(FirebaseAuth.getInstance().getCurrentUser().getUid());
      query.addListenerForSingleValueEvent(new ValueEventListener() {
          @Override
          public void onDataChange(DataSnapshot dataSnapshot) {
              for (DataSnapshot singleSnapshot : dataSnapshot.getChildren()) {
                  Log.d(TAG, "onDataChange: found friend----------------**: " + singleSnapshot.getValue(User.class).toString());
  
                  mFriends.add(singleSnapshot.child(getString(R.string.field_user_id)).getValue().toString());
  
                  Log.d(TAG, "onDataChange: Freinds user id: " + mFriends.toString() );
              }
  
              updateFriendsList();
          }
  
          @Override
          public void onCancelled(DatabaseError databaseError) {
  
          }
      });
  }
  </code></pre>