Problem Realm boolean and mysql

0

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));
            }
        }
    
asked by Ferran 13.02.2018 в 00:43
source

1 answer

0

In the end I found a solution. I have modified the data type of the mysql table by varchar and I have given values of true and false. I was very much helped by the contribution you made to remove the quotes but the Realm class did not assume 1/0 as true / false and jumped an error to understand that an int could not be a boolean.

It's a bit of a problem but I have to finish the app and I have not found another option. Although I could also keep the mysql table with data boolean and json with php transform the values to true / false.

I really do not know which of the two options is cleaner. I hope that other people serve them.

Greetings!

    
answered by 16.02.2018 / 21:13
source