0

I want to retrieve child values by date. The date which exist in firebase is inserted in string datatypes though datepicker of android UI page.

enter image description here

  total_report = new TotalReport();
    FirebaseAuth firebaseAuth = FirebaseAuth.getInstance();
    DatabaseReference ref = FirebaseDatabase.getInstance().getReference(Objects.requireNonNull(firebaseAuth.getUid()));
    DatabaseReference dbs = ref.child("Running Report");
    list = new ArrayList<>();
    adapter = new ArrayAdapter<String>(this, R.layout.monthly_info, R.id.monthlyInfo, list);
    dbs.addValueEventListener(new ValueEventListener() {
        @Override
        public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
            for (DataSnapshot ds : dataSnapshot.getChildren()) {
                total_report = ds.getValue(TotalReport.class);
                list.add(total_report.getUserDate() + "       " + total_report.getUserDistance() + "                       " + total_report.getUserDuration() + "                              " + total_report.getUserPace());
            }
            list_View_month.setAdapter(adapter);
        }
  • 2
    Sounds like a nice use-case. Can you edit your question to show what you tried already, and where you got stuck? If it is related to filtering the dates, that might be caused by the format in which you store the dates, and I recommend reading my answers here https://stackoverflow.com/a/41553469, and https://stackoverflow.com/a/41553469 – Frank van Puffelen Oct 10 '18 at 13:36
  • As per my code, it prints all the child values in list but i need the child values by month/week. – Pankaj Kumar Oct 11 '18 at 08:59
  • There is no way to get nodes by "month" of "week" with your current data structure. Consider storing them as separate `month` and `week` properties, to simplify querying for them. This kind of data duplication is quite common when using NoSQL databases. If this is new to you, I recommend checking out [NoSQL data modeling](https://highlyscalable.wordpress.com/2012/03/01/nosql-data-modeling-techniques/) and [Firebase for SQL developers](https://www.youtube.com/playlist?list=PLl-K7zZEsYLlP-k-RKFa7RyNPa9_wCH2s). – Frank van Puffelen Oct 11 '18 at 14:49
  • Is it possible to get child values for a particular month. – Pankaj Kumar Oct 11 '18 at 17:23
  • Your current format looks European, with the month in the middle. Firebase only allows prefix matches in filters, so won't be able to find a string in the middle. That why I recommended storing the month and week in separate properties. – Frank van Puffelen Oct 11 '18 at 19:49

0 Answers0