I have this bank structure that is this
InmyclassIhaveafunctioncalledgetLocal(),whereitwouldtakethenameIguatemi.ofthisstructure.Butwhenperformingthequeryitisreturningasnull.
Followmyclasswiththefunctionsbelow:
publicclassMesa{privateStringID;privateStringLocal;privateDatabaseReferencereference;privateStringNFC;publicMesa(){}publicvoidSalvar(){DatabaseReferencereference=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 better the question I'll put as I'm 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.model.Mesa;
import static meals.com.meals.R.array.Restaurante_KFC_Pratos; import static meals.com.meals.R.array.Restaurante_McDonalds_Pratos;
public class Make Request 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);
}
}