I'm not able to rescue a child's pushId from Firebase.
In the mClientDatabaseReference.addValueEventListener > > onDataChange I get the value but I can not assign it to the object.
// Carrega os dados do mClienteAutoComplete
mClientDatabaseReference.addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(DataSnapshot dataSnapshot) {
clientList = new ArrayList<>();
for (DataSnapshot dados: dataSnapshot.getChildren()) {
dados.getKey(); <-- OBJETO QUE NÃO CONSIGO ADICIONAR
Client client = dados.getValue(Client.class);
clientList.add(client);
}
ClientAutoCompleteAdapter adapter = new ClientAutoCompleteAdapter(LoansAddActivity.this, clientList);
mClienteAutoComplete.setAdapter(adapter);
Toast.makeText(LoansAddActivity.this, "List: "+ mClienteAutoComplete, Toast.LENGTH_SHORT).show();
}
@Override
public void onCancelled(DatabaseError databaseError) {
}
});
In the mClientAutoComplete.setOnItemClickListener method, I can retrieve any data in my Client model, but I can not retrieve the object identifier from the Ex:
mClienteAutoComplete.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> adapterView, View view, int i, long l) {
Client clientItem = (Client) adapterView.getItemAtPosition(i);
Toast.makeText(LoansAddActivity.this, "Client item: '"+clientItem.getNome()+"'", Toast.LENGTH_SHORT).show(); // CONSIGO PEGAR O VALOR getNome, getTelefone... menos a pushId do registro
}
});
In my model class do I have to reference something for the object to recognize the object identifier?
Follow the MODEL code:
package com.deson.agiemprestimos.model;
/**
* Created by Deson on 18/04/2018.
*/
public class Client {
private String nome;
private String telefone;
private String cpf;
private String rg;
private String rua;
private String bairro;
public Client() {
}
public Client(String nome, String telefone, String cpf, String rg, String rua, String bairro) {
this.nome = nome;
this.telefone = telefone;
this.cpf = cpf;
this.rg = rg;
this.rua = rua;
this.bairro = bairro;
}
public String getNome() {
return nome;
}
public void setNome(String nome) {
this.nome = nome;
}
public String getTelefone() {
return telefone;
}
public void setTelefone(String telefone) {
this.telefone = telefone;
}
public String getCpf() {
return cpf;
}
public void setCpf(String cpf) {
this.cpf = cpf;
}
public String getRg() {
return rg;
}
public void setRg(String rg) {
this.rg = rg;
}
public String getRua() {
return rua;
}
public void setRua(String rua) {
this.rua = rua;
}
public String getBairro() {
return bairro;
}
public void setBairro(String bairro) {
this.bairro = bairro;
}
}