How to get value of last node added to the database

Joe

I'm trying to access a certain value within the last added Firebase node. In my database I have a set of Clients, which through my app, can be added to. Inside a client there's a piece of information titled 'clientName'. I would like to get this value.

enter image description here

Once I get the value, I'm trying to give a toast message showing that value.

Here is my code inside the onClick method of my button. I'm not sure why it's not working. If you know of another way I could do this or a way to fix my current code I'd really appreciate it!

Thanks in advance guys!

my_button[bt].setOnClickListener(new View.OnClickListener() {
                        @Override
                        public void onClick(View v) {
                            if (my_button[Index].getId() == ((ImageButton) v).getId()) {
                                String bla = (String) getIntent().getExtras().get("id");
                                String address = "https://console.firebase.google.com/project/cssecond-92a2d/database/data/clients/" +bla+"/clientName";
                                Firebase ref = new Firebase(address);
                                ref.addListenerForSingleValueEvent(new ValueEventListener() {
                                    @Override
                                    public void onDataChange(com.firebase.client.DataSnapshot dataSnapshot) {
                                        String value = (String) dataSnapshot.getValue();
                                        Toast.makeText(HomePageNews.this,"In your hands you have: "+ value ,Toast.LENGTH_LONG).show();

                                    }

                                    @Override
                                    public void onCancelled(FirebaseError firebaseError) {

                                    }
                                });

                            }
                        }
                    });
Alex Mamo

Everything looks fine in your code. The problem is this line of code:

String bla = (String) getIntent().getExtras().get("id");

The id that is returning from that intent is null, so your reference is also null. In order to fix this, you need to change the code to get the correct value from the intent that is coming from your previous activity and than it should work.

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

How to get the last value from the database

From Dev

How to get the last value from the database

From Dev

How to get the last node value in xml

From Dev

How to get the last node value in xml

From Dev

Get the last value in a node in Firebase database Ionic 3

From Dev

MySQL get name of last added value on group by query

From Dev

Query in mongoDB to get records with different value and last added

From Java

How to get the last value of an ArrayList

From Dev

How to make the scrollView automatically scrolls to the last added value/text

From Dev

how to make jquery check the last value added in a form?

From Dev

How to make the scrollView automatically scrolls to the last added value/text

From Dev

how to get last 10 added records in sqlite table in iphone

From Dev

Swift 3.0, Firebase: How to get last added record

From Dev

How to get the attribute value of the last element?

From Dev

how to get specific last decimal float value

From Dev

How to get last record / max value

From Dev

How to get last value when subscribing to an Observable?

From Dev

How to get last value with condition in postgreSQL?

From Dev

How to get last value from VLookup?

From Dev

How to get the last value from multiple checkbox?

From Dev

How to get last recent value only

From Dev

how to get last time stamp value:mysql

From Dev

how to get last value in srcset property in jquery?

From Dev

How to get to the second last value using xpath?

From Dev

Cytoscape dynamically style last added node only

From Dev

How to return all records that were added to the database within the last 7 days from current date

From Dev

How to get only last iteration value while fetching data from the database,I've tried Getting values as JSON format

From Dev

How can we copy only the new data items that are added at one node to another node in firebase database

From Dev

How get get previous node value in mustache

Related Related

  1. 1

    How to get the last value from the database

  2. 2

    How to get the last value from the database

  3. 3

    How to get the last node value in xml

  4. 4

    How to get the last node value in xml

  5. 5

    Get the last value in a node in Firebase database Ionic 3

  6. 6

    MySQL get name of last added value on group by query

  7. 7

    Query in mongoDB to get records with different value and last added

  8. 8

    How to get the last value of an ArrayList

  9. 9

    How to make the scrollView automatically scrolls to the last added value/text

  10. 10

    how to make jquery check the last value added in a form?

  11. 11

    How to make the scrollView automatically scrolls to the last added value/text

  12. 12

    how to get last 10 added records in sqlite table in iphone

  13. 13

    Swift 3.0, Firebase: How to get last added record

  14. 14

    How to get the attribute value of the last element?

  15. 15

    how to get specific last decimal float value

  16. 16

    How to get last record / max value

  17. 17

    How to get last value when subscribing to an Observable?

  18. 18

    How to get last value with condition in postgreSQL?

  19. 19

    How to get last value from VLookup?

  20. 20

    How to get the last value from multiple checkbox?

  21. 21

    How to get last recent value only

  22. 22

    how to get last time stamp value:mysql

  23. 23

    how to get last value in srcset property in jquery?

  24. 24

    How to get to the second last value using xpath?

  25. 25

    Cytoscape dynamically style last added node only

  26. 26

    How to return all records that were added to the database within the last 7 days from current date

  27. 27

    How to get only last iteration value while fetching data from the database,I've tried Getting values as JSON format

  28. 28

    How can we copy only the new data items that are added at one node to another node in firebase database

  29. 29

    How get get previous node value in mustache

HotTag

Archive