1

I'm Setting a Call log application that retrieve the data of Calls from one Firebase database Child and the name of the equivalent Contact from another Child. I can run the queries and they retrieve the data but don't know how to cast then to the same Adaptor.

I'm using Android Studio and Firebase realtime database with little experience in both. My best result is this:

                public void onChildAdded(@NonNull DataSnapshot dataSnapshot, @Nullable String s) {
                    Person personList = dataSnapshot.getValue(Person.class);
                    String nombre = dataSnapshot.child("mNumber").getValue().toString();

                    Query query = mFirebaseDatabase.getReference("Names")
                            .orderByChild(nombre);
                    query.addListenerForSingleValueEvent(
                            new ValueEventListener() {
                              @Override
                              public void onDataChange(DataSnapshot dataSnapshot) {
                                    if (dataSnapshot.exists()) {
                                        for (DataSnapshot snapshot : dataSnapshot.getChildren()) {
                                            String artist = snapshot.getValue().toString();
                                            Person personName = snapshot.getValue(Person.class);
                                            mContactsAdapter.add(personName);

                                        }
                                    }
                                }
                                @Override
                                public void onCancelled(DatabaseError databaseError) {

                                }
                            });
                    mContactsAdapter.add(personList);
                }

This is how Firebase Realtime Database looks like

{
  "Missed" : {
    "-LmPZ-AOWIPSfEr-XK1v" : {
      "mCheck" : "Check Out",
      "mDate" : "16-08-19",
      "mNumber" : "6505551212",
      "mTime" : "15:13"
    },
    "-LmQGRvIYzAqqfmn94xU" : {
      "mCheck" : "Check Out",
      "mDate" : "16-08-19",
      "mNumber" : "6505551213",
      "mTime" : "18:32"
    }

  },
  "Names" : {
    "6505551212" : {
      "mName" : "Bruce Wills"
    },
    "6505551213" : {
      "mName" : "Peter Pan"
    }
  }
}

for now, the result looks like this Screenshot

I want the same card to have the name AND the rest of the data.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
Bro el Khateeb
  • 203
  • 2
  • 7

1 Answers1

0

I can run the queries and they retrieve the data but don't know how to cast then to the same Adaptor

There is no way you can pass two different queries to the same adapter instance. The best solution I can think of right now is to create an array or an ArrayList of the combined results in your client side code and then simply pass it to an ArrayAdapter. It's not the best solution since you'll need to query your database twice, but it will solve your problem.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • Can you recommend a specific code for the solution? – Bro el Khateeb Aug 21 '19 at 10:21
  • *Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow*. What I can say is, you should create two nested queries and to display the results in a `ListView` using an `ArrayAdapter`, please see my answer from this **[post](https://stackoverflow.com/questions/48622480/showing-firebase-data-in-listview)**. So you should make your own attempt given the information in the answer and ask another question if something else comes up. – Alex Mamo Aug 21 '19 at 10:30