I am getting Firebase data, since I have debugged and in the getValue the data appears without any problem, but when I want to assign it to homes, the fields are null
This is the main code where I get the data from Firebase and try to add it to an adapter
myDatabase.getRoot().addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
casasList.removeAll(casasList);
for (DataSnapshot childSnapshot: dataSnapshot.getChildren()) {
Casas casas = childSnapshot.getValue(Casas.class);
casasList.add(casas);
}
adapter.notifyDataSetChanged();
}
I also add the Casas class where they have their constructors and their methods getters and setters public class Casas { String mail, sale, purchase, address, id;
public Casas(String correo, String venta, String compra, String direccion) {
this.correo = correo;
this.venta = venta;
this.compra = compra;
this.direccion = direccion;
}
public Casas() {
}
public String getCorreo() {
return correo;
}
public void setCorreo(String correo) {
this.correo = correo;
}
public String getVenta() {
return venta;
}
public void setVenta(String venta) {
this.venta = venta;
}
public String getCompra() {
return compra;
}
public void setCompra(String compra) {
this.compra = compra;
}
public String getDireccion() {
return direccion;
}
public void setDireccion(String direccion) {
this.direccion = direccion;
}
}
This is the class where I build my adapter
public class RecyclerViewAdapter extends RecyclerView.Adapter {
ArrayList<Casas> casasList;
public RecyclerViewAdapter(ArrayList<Casas> casasList) {
this.casasList = casasList;
}
@NonNull
@Override
public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
View view = LayoutInflater.from(parent.getContext()).inflate(R.layout.item_casadecambio,parent,false);
ViewHolder viewHolder = new ViewHolder(view);
return viewHolder;
}
@Override
public void onBindViewHolder(@NonNull ViewHolder holder, int position) {
Casas casa = casasList.get(position);
holder.compra.setText(casa.getCompra());
holder.venta.setText(casa.getVenta());
holder.direccion.setText(casa.getDireccion());
}
@Override
public int getItemCount() {
return casasList.size();
}