SQLite
 sql >> Base de Dados >  >> RDS >> SQLite

dados carregados do banco de dados SQLitE não estão sendo salvos na classe de modelo ArrayList android


Tente com o seguinte código.
 class Adapter extends RecyclerView.Adatper<RecyclerViewAdapter.RecyclerViewHolder>(){
 //add new method in adapter class
 Public void dataChange(ArrayList<Model> itemList){
  //update your previous list with the new list
  previousList = itemList;
  notifyDataSetChanged()
  }

}


public void ReadSqliteData(Context context){
ArrayList<Model> list = new ArrayList<>();
Adpter adpter = new Adpter(list,context);
SQLiteDatabase database = getWritableDatabase();
Cursor cursor = database.rawQuery("Select name, image from orders",null);
while (cursor.moveToNext()){
Model model = new Model();
model.setImage(cursor.getString(0));            
model.setName(cursor.getString(1));    
list.add(model);
}
//call adapter dataChange() method from here
adpter.dataChange(list);
cursor.close();
database.close();
}