i have a little problem with my simple firebase based app. Im trying to retrieve data from database like this:
public void readbuttonposition() {
database.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
for (DataSnapshot buttonSnapshot: dataSnapshot.getChildren()){
ButtonPosition buttonPosition = buttonSnapshot.getValue(ButtonPosition.class);
String user = buttonPosition.getbutton_position();
if (user == "1"){
button2.setVisibility(View.GONE);
button3.setVisibility(View.VISIBLE);
}
else if (user == "0"){
button2.setVisibility(View.VISIBLE);
button3.setVisibility(View.GONE);
}
}
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
}
simply there are two buttons, each of them gives values: 0 and 1. As you can see, when button2
is VISIBLE
then button3
is GONE
. Thats allright everything is fine when im pressing the buttons. But when i want to restart the app and launch it again there's always button2
visible, even when database
button_position is valued as 1 which should make button3
visible.. Here's a screenshot of firebase tree
and
DatabaseReference
path:
database = FirebaseDatabase.getInstance().getReference("users").child(user.getUid()).child("hours");
im also retrieving start_hour
this way and it works fine, so where i failed ? :D
@edit ButtonPosition.class
code
public class ButtonPosition {
String button_position;
public ButtonPosition(){
}
public ButtonPosition(String button_position) {
this.button_position = button_position;
}
public String getbutton_position(){
return button_position;
}
}