0
I have this bank structure that is this
In my class I have a function called getLocal (), where she would take the name Iguatemi. of this structure. However when performing the query it is returning as null.
Follow my class with the functions below:
public class Mesa {
private String ID;
private String Local;
private DatabaseReference reference;
private String NFC;
public Mesa() {
}
public void Salvar(){
DatabaseReference reference = ConfiguracaoFirebase.getReferencia();
reference.child("Mesas").child(getID()).setValue(this);
}
@Exclude
public String getID() {
return ID;
}
public void setID() {
reference = ConfiguracaoFirebase.getReferencia().child("Mesas");
this.ID = reference.push().getKey();
}
public String getLocal(String Txt) {
DatabaseReference reference = ConfiguracaoFirebase.getReferencia();
reference.child("Mesas").child(Txt).child("local");
reference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
String texto = (String) dataSnapshot.getKey();
}
@Override
public void onCancelled(DatabaseError databaseError) {
Log.e("TAG", databaseError.getMessage());
}
});
return Local;
}
public void setLocal(String local) {
Local = local;
}
}
Please help me with what I’m missing.
To get the question better I will put as I am doing in Activity.
package meals.com.meals.activity.Activity;
import android.app.Activity; import android.content.Intent; import android.support.v7.app.Appcompatactivity; import android.os.Bundle; import android.view.View; import android.widget.Adapterview; import android.widget.Arrayadapter; import android.widget.Spinner; import android.widget.Textview;
import Meals.com.Meals. R; import Meals.com.Meals.activity.modelo.Mesa;
import Static Meals.com.Meals.R.array.Restaurante_kfc_pratos; import Static Meals.com.Meals.R.array.Restaurante_mcdonalds_dishes;
public class Effectedido extends Appcompatactivity {
private TextView InfoMesa;
private Spinner SpinnerRestaurante;
private Spinner SpinnerPratos;
private Mesa Mesas;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_fazer_pedido);
InfoMesa = (TextView) findViewById(R.id.textViewInfoMesa);
SpinnerRestaurante = (Spinner)findViewById(R.id.spinnerRestaurante);
SpinnerPratos = (Spinner) findViewById(R.id.spinner_pratos);
Intent intent = getIntent();
Bundle bundle = intent.getExtras();
String NFC = bundle.getString("TagNFC");
Mesa Mesas = new Mesa();
Mesas.RecuperarMesa(NFC);
InfoMesa.setText("Você esta em " + Mesas.getLocal() + " " + "na mesa \n" + NFC);
// InfoMesa.setText("Você esta na na mesa \n" + NFC);
}
}
If I want to take the Name of the place in String and return, how would that look? Because how am I getting The Table class.class I would get it all right right?
– IMoonBlackI
The "getLocal()" method should be a common getter method. And then you could call the.getLocal() table to have access to the String returned by it. And recover the database data through a separate method, which would return a Mesa.
– Cas
I think I’m really dumb, I don’t know if you can pass an email or something to help me more..... follow my ai 19 997749701 can call me
– IMoonBlackI
Inside the Recover Table I put this part of the code too because I have to search through the ID
public Mesa RecuperarMesa (String Txt){
Mesa mesa = new Mesa();
DatabaseReference reference =ConfiguracaoFirebase.getReferencia();
reference.child("Mesas").equalTo(Txt);
– IMoonBlackI
From what your code shows, you saved the table using the ID. So to search using the ID just give a Reset.Child("Tables"). Child(ID). With this you already have the table reference with the ID you want.
– Cas