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.
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) {
}
});
}
}
});
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.
Comments