mardi 16 février 2016

Inserting Array List in Sqllite

I am downloading some data over network in JSON format and after retrieving it, I am storing it in SqlLiteDatabase. Earlier I use to fetch the data and display it in RecyclerView but now I am storing it in SqlLite Database and then displaying it in RecyclerView. However the data get stored successfully as it return true but when I display the data, it shows nothing. To check if the data exist or not after being added, I get the number of count on available data and it returns 0.

Here are the codes:

public boolean create(List<PGCardItemReturn> objectPg) {

    SQLiteDatabase db = this.getWritableDatabase();

    PGCardItemReturn lastItem = null;;
    db.beginTransaction();
    String sql = "Insert or Replace into tenant_pg (id,furnishing,area,price,numberofbeds,image_url) values(?,?,?,?,?,?)";
    SQLiteStatement insert = db.compileStatement(sql);
    for(int i=0;i<objectPg.size();i++){
        PGCardItemReturn item = objectPg.get(i);
        if(i == (this.count()-1)){
            lastItem = item;
        }
        insert.bindString(1, item.getId());
        insert.bindString(2, item.getFurnishing());
        insert.bindString(3, item.getArea());
        insert.bindString(4, item.getPrice());
        insert.bindString(5, item.getNumberofbeds());
        insert.bindString(6, item.getImageUrl());

        insert.execute();
    }



    db.endTransaction();



    return true;
}

In Main Acvitiy:

boolean add = new TableControllerTenant_pg(getApplicationContext()).create(listPG);

Thanks in advance!

Aucun commentaire:

Enregistrer un commentaire