title: How to sort my RecyclerView according to date and time
body: <p>As the image shows, my list is not being sorted according date and time</p>
  
  <p>RecyclerView Image
  <a href="https://i.stack.imgur.com/uQcBk.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/uQcBk.png" alt="enter image description here"></a>
   and this is my firebase structure </p>
  
  <p>Firebase Image
  <a href="https://i.stack.imgur.com/Yfvn3.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Yfvn3.png" alt="enter image description here"></a></p>
  
  <blockquote>
    <p>Add Appointment.java -> this is how i add my data to firebase</p>
  </blockquote>
  
  <pre><code>  public class AddAppointment extends AppCompatActivity {
  
      private FirebaseAuth firebaseAuth;
      private FirebaseUser mCurrentUser;
  
  
      private EditText dateApp,timeApp,nameTxt,addressTxt,telTxt;
      int mYear,mMonth,mDay,mHour,mMinute;
      private Button saveBtn;
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_add_appointment);
          Firebase.setAndroidContext(this);
  
  
          nameTxt = (EditText) findViewById(R.id.nameText);
          addressTxt= (EditText) findViewById(R.id.addressText);
          telTxt = (EditText) findViewById(R.id.telText);
          dateApp = (EditText)findViewById(R.id.dateAppointment);
          timeApp = (EditText)findViewById(R.id.timeAppointment);
          dateApp.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  datePic();
              }
          });
          timeApp.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  timePic();
              }
          });
          saveBtn = (Button)findViewById(R.id.saveBtn);
          saveBtn.setOnClickListener(new View.OnClickListener() {
              @Override
              public void onClick(View view) {
                  firebaseAuth = FirebaseAuth.getInstance();
                  mCurrentUser = firebaseAuth.getCurrentUser();
                  DatabaseReference db= FirebaseDatabase.getInstance().getReference().child("Email").child(mCurrentUser.getUid()).child("Appointment").push();
                  String name = nameTxt.getText().toString().trim();
                  String address = addressTxt.getText().toString().trim();
                  String tel = telTxt.getText().toString().trim();
                  String date = dateApp.getText().toString().trim();
                  String time = timeApp.getText().toString().trim();
  
                  //Adding values
                  db.child("name").setValue(name);
                  db.child("address").setValue(address);
                  db.child("tel").setValue(tel);
                  db.child("date").setValue(date);
                  db.child("time").setValue(time);
  
                  //Storing values to firebase
                  Toast.makeText(AddAppointment.this,"Saved",Toast.LENGTH_SHORT).show();
                  Intent mainIntent = new Intent(AddAppointment.this,MainActivity.class);
                  startActivity(mainIntent);
              }
          });
      }
      public  void datePic()
      {
          final Calendar c = Calendar.getInstance();
          mYear = c.get(Calendar.YEAR);
          mMonth = c.get(Calendar.MONTH);
          mDay = c.get(Calendar.DAY_OF_MONTH);
  
          DatePickerDialog datePickerDialog = new DatePickerDialog(this,new DatePickerDialog.OnDateSetListener(){
              @Override
              public void onDateSet(DatePicker view, int year, int monthOfYear, int dayOfMonth){
                  mYear = year;
                  mMonth = monthOfYear+1;
                  mDay = dayOfMonth;
                  dateApp.setText((mDay+"-"+mMonth+"-"+mYear));
              }
          },mDay,mMonth,mYear);
          datePickerDialog.getDatePicker().setMinDate(System.currentTimeMillis() - 1000);
          datePickerDialog.show();
      }
      public  void timePic()
      {
          final Calendar c = Calendar.getInstance();
          mHour = c.get(Calendar.HOUR_OF_DAY);
          mMinute = c.get(Calendar.MINUTE);
  
          TimePickerDialog timePickerDialog = new TimePickerDialog(this,new TimePickerDialog.OnTimeSetListener(){
              @Override
              public void onTimeSet(TimePicker view, int hourOfDay, int minute){
                  int hour = hourOfDay % 12;
                  timeApp.setText(String.format("%02d:%02d %s", hour == 0 ? 12 : hour,
                          minute, hourOfDay &lt; 12 ? "a.m." : "p.m."));
              }
          },mHour,mMinute,false);
          timePickerDialog.show();
      }
  }
  </code></pre>
  
  <blockquote>
    <p>AppointmentData.java -> this is my data setup</p>
  </blockquote>
  
  <pre><code>    public class AppointmentData {
  
      private String name,tel,address,time,date;
  
      public AppointmentData() {
      }
  
      public void setName(String name) {
          this.name = name;
      }
  
      public void setTel(String tel) {
          this.tel = tel;
      }
  
      public void setAddress(String address) {
          this.address = address;
      }
  
      public void setTime(String time) {
          this.time = time;
      }
  
      public void setDate(String date) {
          this.date = date;
      }
  
      public AppointmentData(String name, String tel, String address, String time, String date) {
          this.name=name;
          this.tel=tel;
          this.address=address;
          this.time=time;
          this.date=date;
      }
  
      public String getName() {
          return name;
      }
  
      public String getTel() {
          return tel;
      }
  
      public String getAddress() {
          return address;
      }
  
      public String getDate() {
          return date;
      }
  
      public String getTime() {
          return time;
      }
  
  }
  </code></pre>
  
  <blockquote>
    <p>ViewAppointment.java -> this is how i display my recyclerview</p>
  </blockquote>
  
  <pre><code> public class ViewAppointment extends AppCompatActivity {
  
      private FirebaseAuth firebaseAuth;
      private FirebaseUser mCurrentUser;
      private DatabaseReference db;
      private RecyclerView recyclerView;
      private FirebaseRecyclerAdapter&lt;AppointmentData,myViewHolder&gt; mAdapter;
  
  
      @Override
      protected void onCreate(Bundle savedInstanceState) {
          super.onCreate(savedInstanceState);
          setContentView(R.layout.activity_view_appointment);
  
  
          recyclerView=(RecyclerView)findViewById(R.id.recycle);
          recyclerView.setLayoutManager(new LinearLayoutManager(this));
          firebaseAuth = FirebaseAuth.getInstance();
  
          mCurrentUser = firebaseAuth.getCurrentUser();
          db= FirebaseDatabase.getInstance().getReference().child("Email").child(mCurrentUser.getUid()).child("Appointment");
          db.keepSynced(true);
          mAdapter= new FirebaseRecyclerAdapter&lt;AppointmentData, myViewHolder&gt;(
  
                  AppointmentData.class,R.layout.model,myViewHolder.class,db
          ) {
  
  
              @Override
              protected void populateViewHolder(final myViewHolder viewHolder, final AppointmentData model, final int position) {
                  viewHolder.nameTxt.setText(model.getName());
                  viewHolder.dateApp.setText(model.getDate());
                  viewHolder.timeApp.setText(model.getTime());
                  viewHolder.mapBtn.setText("Map");
                  viewHolder.detailBtn.setText("Detail");
                  viewHolder.deleteBtn.setText("Delete");
                  viewHolder.editBtn.setText("Edit");
                  Log.e("myFirebase UID", mAdapter.getRef(position).getKey());
                  viewHolder.editBtn.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          Intent i = new Intent (view.getContext(), UpdateAppointment.class);
                          i.putExtra("NAME_KEY",model.getName());
                          i.putExtra("ADDRESS_KEY",model.getAddress());
                          i.putExtra("TEL_KEY",model.getTel());
                          i.putExtra("DATE_KEY",model.getDate());
                          i.putExtra("TIME_KEY",model.getTime());
                          view.getContext().startActivity(i);
                          Log.e("Item Click position",""+position);
                          mAdapter.getRef(+position).removeValue();
                      }
                  });
                  viewHolder.detailBtn.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          Intent i = new Intent (view.getContext(), DetailActivity.class);
                          i.putExtra("NAME_KEY",model.getName());
                          i.putExtra("ADDRESS_KEY",model.getAddress());
                          i.putExtra("TEL_KEY",model.getTel());
                          i.putExtra("DATE_KEY",model.getDate());
                          i.putExtra("TIME_KEY",model.getTime());
                          view.getContext().startActivity(i);
                      }
                  });
                  viewHolder.mapBtn.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          Intent i = new Intent (view.getContext(), Distance.class);
                          i.putExtra("ADDRESS_KEY",model.getAddress());
                          view.getContext().startActivity(i);
                      }
                  });
                  viewHolder.deleteBtn.setOnClickListener(new View.OnClickListener() {
                      @Override
                      public void onClick(View view) {
                          Log.e("Item Click position",""+position);
                          mAdapter.getRef(+position).removeValue();
                      }
                  });
              }
          };
          recyclerView.setAdapter(mAdapter);
  
      }
      public static class myViewHolder extends RecyclerView.ViewHolder{
          private TextView nameTxt,dateApp,timeApp;
          private Button detailBtn,mapBtn,deleteBtn,editBtn;
  
          public myViewHolder(View itemView){
              super(itemView);
              nameTxt=(TextView)itemView.findViewById(R.id.nameTxt);
              dateApp= (TextView) itemView.findViewById(R.id.dateAppointment);
              timeApp=(TextView)itemView.findViewById(R.id.timeAppointment);
              mapBtn = (Button) itemView.findViewById(R.id.mapBtn);
              detailBtn = (Button) itemView.findViewById(R.id.detailBtn);
              deleteBtn = (Button) itemView.findViewById(R.id.deleteBtn);
              editBtn = (Button) itemView.findViewById(R.id.editBtn);
          }
      }
  
  
  }
  </code></pre>