-2
Hello, for some reason the travel variable is not adding 1 more to the Trips field in Firebase, when the pegLoc button is pressed, could you help me? , Follows below code:
public class Mainactivity extends Appcompatactivity { private Edittext edtUsuario;
private Button pegLoc;
FirebaseDatabase database;
DatabaseReference mDatabase;
Placa placa;
int viagem = 0;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_PORTRAIT);
pegLoc = findViewById(R.id.btnPegarLoc);
edtUsuario = findViewById(R.id.edtUsuario);
placa = new Placa();
database = FirebaseDatabase.getInstance();
mDatabase = database.getReference("localização");
trocarTelas();
}
private void trocarTelas() {
pegLoc.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if (TextUtils.isEmpty(edtUsuario.getText().toString().toUpperCase())) {
edtUsuario.setError("Insira o Nome do Usuário");
edtUsuario.requestFocus();
} else {
viagem = viagem + 1;
placa.setPlaca(edtUsuario.getText().toString());
mDatabase.child("Dados da Viagem").child("loc_Status_Viagem").setValue("Iniciada");
mDatabase.child("Viagens").child(placa.getPlaca()).setValue(viagem);
mDatabase.child("Dados da Viagem").child("Placa").setValue(placa.getPlaca());
mDatabase.child("Dados da Viagem").child("loc_Hora").setValue(AppUtil.getHoraAtual());
mDatabase.child("Dados da Viagem").child("loc_Data").setValue(AppUtil.getDataAtual());
Intent intent = new Intent(getApplicationContext(), Localizacao.class);
startActivity(intent);
}
}
});
}
}
The question n ta mt clear, so tell me one thing, when you click the button, the system manages to fall into Else? to perform the +1?
– Renan
Simm, screen change and all, however, whenever I click to get the location, it keeps at 1, in firebase, instead of adding up 1 more
– Paulo Henrique
Other data is changed correctly? ous other tbm n changes in firebase?
– Renan
Yes, everyone changes normally, only the one in particular does not change
– Paulo Henrique
By seeing q to, the problem is q vc has q first update the card, Tries to invert the lines mDatabase.Child("Travel"). Child(plate.getPlaca()). setValue(trip); and mDatabase.Child("Travel Data"). Child("Plate"). setValue(plate.getPlaca());
– Renan
Still the same thing : /
– Paulo Henrique
Post the structure of your firebase
– Renan
setPlaca(edtUsuario.gettext(). toString()); mDatabase.Child("Travel Data"). Child("loc_Status_Viagem"). setValue("Initiated"); mDatabase.Child("Travels"). Child(plate.getPlaca()). setValue(trip); mDatabase.Child("Trip Data"). Child("Board"). setValue(plate.getPlaca(); mDatabase.Child("Travel Data"). Child("loc_Hora"). setValue(AppUtil.getHoraAtual());
 mDatabase.child("Dados da Viagem"). child("loc_Data"). setValue(AppUtil.getDataAtual());
– Paulo Henrique
No Paul, asked the question how his firebase bank is structured
– Renan
Ready put
– Paulo Henrique