-1

I want to take data inside a folder of my Realtime Database that looks like this:

this is the realtime database look like

I have this code for getting the date range data and showing it in RecycleView .

    DatabaseReference db = FirebaseDatabase.getInstance ( ).getReference ( );
        DatabaseReference pendingRef = db.child ("Users").child ("Pending");

        Query queryByKey = pendingRef.orderByKey ()
                .startAt ("*" + tanggalawal)
                .endAt ("*" + tanggalakhir + "\uf8ff");

        recView = (RecyclerView)findViewById (R.id.recview);
        recView.setLayoutManager (new LinearLayoutManager (this));

        FirebaseRecyclerOptions<Model> options =
                new FirebaseRecyclerOptions.Builder<Model>()
                        .setQuery(queryByKey, Model.class)
                        .build();

        adapter = new MyAdapter (options);
        recView.setAdapter (adapter);

How can I get the DataPelanggan data inside of it?

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • *i want to take data inside an folder of my realtime database* Which one? – Alex Mamo Dec 07 '21 at 09:19
  • in DataPelanggan, im gonna take the currentDateandTime, date, fullName, nik, but after i took the data, im gonna put them into recycleview fragmnet –  Dec 07 '21 at 09:29
  • So you only want to get the value of `currentDateAndTime`, `date`, `fullName` and `nik` that exist inside DataPelanggan? If this what you want, I don't see any reason you have used a Query. – Alex Mamo Dec 07 '21 at 09:31
  • oh ya?, i don't know bout that cause i've been following some of youtube video of how to use startAt and endAt, what should i change to?, i've follow your way to search range data too https://stackoverflow.com/questions/70077152/search-firebase-realtime-database-base-on-6-digit-in-front-of-the-child-data-i –  Dec 07 '21 at 09:46
  • So you followed that, and what's the issue? – Alex Mamo Dec 07 '21 at 10:02
  • it surely took data from the range, but im going to show the data at the recyleview. with the one i've using now is show blank on fragment, but when i manually put the data outside of DataNasabah folder, its work properly –  Dec 07 '21 at 10:18

1 Answers1

0

When you are using the Firebase-UI library for Android, it means that the adapter will be able to display only a flat list of objects based on the query that you pass in, creating one ViewHolder object for each element.

Since your actual data is located beneath nodes like DataPelanggan, KTP, and so on, that library isn't really helpful. If you can change the database schema like this:

Firebase-root
  |
  --- Pending
       |
       --- *20211127...
             |
             --- type: "DataPelanggan" 
             |
             --- currentDateAndTime: "*20211127..."
             |
             --- date: "16/10/1999"
             |
             --- fullName: "a"
             |
             --- nik: "4444...."

It will work because we have added the node key as a field right under each object. In this way, we removed that extra level in the schema and your code may remain unchanged.

Alex Mamo
  • 130,605
  • 17
  • 163
  • 193
  • i've tring to make sort of database look like that but i got problem with it,https://stackoverflow.com/questions/70225677/how-can-i-put-data-outside-of-child-in-firebase-i-having-problem-look-like-this this is the problem –  Dec 07 '21 at 11:12
  • No. Have you tried the solution in my answer? – Alex Mamo Dec 07 '21 at 11:15
  • well ofc it's work, but i cant arrange them into that look realtime databse –  Dec 07 '21 at 11:17
  • What is the order that you get? And what is the order that you want? I don't understand that. – Alex Mamo Dec 07 '21 at 11:28
  • i want to make a database look like your answer, but i need to put more child data inside there, how can i upload/add data without interfere the other file –  Dec 07 '21 at 11:34
  • Simply remove a call to something like this: `.child("DataPelanggan")`. In this way you will not create that extra level. – Alex Mamo Dec 07 '21 at 11:36
  • but well when i did that, the other folder will gone, its become replace by the non-child data –  Dec 07 '21 at 11:43
  • Without seeing the code and the database structure, I cannot be much of a help. So please post a new question, here on StackOverflow, using its own [MCVE](https://stackoverflow.com/help/mcve), so I and other Firebase developers can help you. – Alex Mamo Dec 07 '21 at 20:18