title: How to show chat list of firebase in android
body: <p>I want to show chat channels in order. Like show that channel first which has recently added a message. Code:</p>
  
  <pre><code>FirebaseDatabase database = FirebaseDatabase.getInstance();
  DatabaseReference myRef = database.getReference();
  myRef.child("dummy").setValue(0);
          myRef.addValueEventListener(new ValueEventListener()
          {
              @Override
              public void onDataChange(DataSnapshot dataSnapshot)
              {
                  if(dataSnapshot != null)
                  {
                      names.clear();
                      for (DataSnapshot child : dataSnapshot.getChildren())
                      {
                          String name = child.getKey();
                          if(!child.getKey().equals("dummy") &amp;&amp; child.getKey().contains(phoneNumber))
                              names.add(name);
                      }
  
                      peopleAdatper = new PeopleAdatper(getApplicationContext(),names,users);
                      listView.setAdapter(peopleAdatper);
                  }
              }
  
              @Override
              public void onCancelled(DatabaseError databaseError)
              {
  
              }
          });
  </code></pre>
  
  <p>My <code>ChatMessage</code> class:</p>
  
  <pre><code>ChatMessage chatMessage = new ChatMessage();
  chatMessage.setMessageText(messageEditText.getText().toString());
  chatMessage.setNo(parentRef);
  chatMessage.setName(sharedPreferences.getString("nickname",""));
  chatMessage.setDuration(duration);
  long time = SystemClock.currentThreadTimeMillis();
  chatMessage.setMessageTime(time);
  myRef.push().setValue(chatMessage);
  myRef.child(childRef).setValue("new");
  </code></pre>
  
  <p>and database structure is: </p>
  
  <pre><code>{
    "0300****644_0333****366" : {
      "-L4b9UHJGuIV311odBXz" : {
        "duration" : "",
        "messageText" : "hel",
        "messageTime" : 0,
        "name" : "Bilal Shahid",
        "no" : "0300****644"
      },
      "0300****644" : "seen",
      "0333****366" : "seen",
      "dummy" : 0
    },
  </code></pre>
  
  <p>Usually firebase show channels in order they created. But i want them to order like we have in simple mobile message app. I have searched a lot about it but didn't found any thing for this scenario. Thank you</p>