I am learning android and I have created an app that manages lots. Use Realm for the persistence of data and retrieve them through retrofit of a Mysql table. When I recover the boolean data from the Batch table, they always appear as false even though the mysql table has values other than 0. The problem is that the Realm Batch model expects a true / false value and finds a value 0/1 . Could this be the error? How can I solve it? I had thought about changing the fields to String, but if possible I would like to keep the field as boolean.
Here the code:
public class Lote extends RealmObject {
@PrimaryKey
private int id;
private String Lote;
private String Producto;
private int Quantidad;
private boolean Activado;
private boolean Defecto;
private int Syncro;
@Required
private Date datalote;
public Lote(){}
public Lote(String lote, String producto, int quantidad, boolean activado, boolean defecto, int syncro)
{
this.id = MyApplication.LoteID.incrementAndGet();
Lote = lote;
Producto = producto;
Quantidad = quantidad;
Activado = activado;
Defecto = defecto;
Syncro = syncro;
this.datalote = new Date();
}
public int getId() {
return id;
}
public String getLote() {
return Lote;
}
public void setLote(String lote) {
Lote = lote;
}
public String getProducto() {
return Producto;
}
public void setProducto(String producto) { Producto = producto; }
public int getQuantidad() {
return Quantidad;
}
public void setQuantidad(int quantidad) {
Quantidad = quantidad;
}
public boolean getActivado() {return Activado; }
public void setActivado(boolean activado) { Activado = activado; }
public boolean getDefecto() {return Defecto; }
public void setDefecto(boolean defecto) {Defecto = defecto; }
public int getSyncro() {return Syncro; }
public void setSyncro(int syncro) { Syncro = syncro; }
public Date getDataLote() { return datalote; }
The code to receive data from the mysql table:
loteCall.enqueue(new Callback<ArrayList<Lote>>() {
@Override
public void onResponse(Call<ArrayList<Lote>> call, Response<ArrayList<Lote>> response) {
ArrayList<Lote> lotesel = response.body();
for(Lote item : lotesel) {
String nomlote = item.getLote();
String producto = item.getProducto();
int quantidad = item.getQuantidad();
boolean activado = item.getActivado();
boolean defecto= item.getDefecto();
int syncro = item.getSyncro();
Date date = item.getDataLote();
realm.beginTransaction();
Lote lote = new Lote(nomlote, producto, quantidad, activado, defecto, syncro);
realm.copyToRealm(lote);
realm.commitTransaction();
txtLotes.setTextColor(txtLotes.getContext().getResources().getColor(R.color.facturapagada));
txtLotes.setText(getString(R.string.txt_dblotesok));
}
}