Someone knows what I did wrong, because I need to double-click the button to pull the value.
package fabiohcnobre.jhotelcolonialdosnobres;
import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.Toolbar;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.TextView;
import com.google.android.gms.common.api.GoogleApiClient;
import com.google.firebase.database.DataSnapshot;
import com.google.firebase.database.DatabaseError;
import com.google.firebase.database.DatabaseReference;
import com.google.firebase.database.FirebaseDatabase;
import com.google.firebase.database.ValueEventListener;
public class settingsActivity extends AppCompatActivity {
FirebaseDatabase database = FirebaseDatabase.getInstance();
DatabaseReference myRef ;
private String TAG;
private String statusdareserva;
private GoogleApiClient client;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_settings);
Toolbar toolbar = (Toolbar) findViewById(R.id.toolbar);
setSupportActionBar(toolbar);
getSupportActionBar().setDisplayHomeAsUpEnabled(true);
Button btnbuscar = (Button) findViewById(R.id.button_buscar);
btnbuscar.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
TextView textview1 = (TextView) findViewById(R.id.TextView1);
EditText editext1 = (EditText) findViewById(R.id.edittext1);
String status = "Falha";
status = ProcuraReserva(editext1.getText().toString());
textview1.setText("1"+ status);
}
});
}
public String ProcuraReserva(String codigodareserva){
// Read from the database
myRef = database.getReference("reserva/"+codigodareserva+"/status");
myRef.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String value = dataSnapshot.getValue(String.class);
statusdareserva = value;
}
@Override
public void onCancelled(DatabaseError error) {
statusdareserva = "Status com falha";
}
});
return statusdareserva;
}
}