Currently I have a ListView, which shows the data stored in Firebase.
I try to send the ID of each stored object, but my "putExtra" only sends the visible data, that is, the name (I have decided that this is the visible data by creating a toString method returning the name in the pojo class)
Pojo:
private String idParcela;
private String nombreParcela;
private int hectareas;
private Date ultimoTratamienetoQuimico;
private Date proximoTratamientoQuimico;
private String fruta;
private String variedad;
private String nombreTratamiento;
private int diasTratarQuimicamente;
//GETTERS SETTERS BUILDERS...
@Override
public String toString(){return nombreParcela; }
Now I will show the 2 functions
ListData collects the data from firebase, and stores it in the listview, with the arrayadapter.
private void listarDatos() {
databaseReference.child("parcelas").addValueEventListener(new ValueEventListener() {
@Override
public void onDataChange(@NonNull DataSnapshot dataSnapshot) {
listaParcelas.clear();
for(DataSnapshot objSnaptshot : dataSnapshot.getChildren()){
Parcela p = objSnaptshot.getValue(Parcela.class);
listaParcelas.add(p);
}
arrayAdapterParcela = new ArrayAdapter<Parcela>(listaParcelas.this, android.R.layout.simple_list_item_1,listaParcelas);
listvListaParcela.setAdapter(arrayAdapterParcela);
}
@Override
public void onCancelled(@NonNull DatabaseError error) {
}
});
listvListaParcela.setOnItemClickListener(new AdapterView.OnItemClickListener() {
@Override
public void onItemClick(AdapterView<?> parent, View view, int i, long l) {
Intent intentEditar = new Intent(listaParcelas.this,editarParcela.class);
intentEditar.putExtra("idParcelaModificable",listvListaParcela.getItemAtPosition(i).toString());
startActivity(intentEditar);
}
});
}
At the time of sending the intentEditar.putExtra only sends the data name and forgets all the data stored but not visible, which it contains (I know that the data is there, since in the debugger it can be observed)