In the below code I get data from database and add them to the court class, finally add the court class to the courtList. But the final courtList's items are the same . All the data are the last data in the database. How can I solve it? Where is my mistake?
Thank's
public List<Court> getListOfCourt(){
List<Court> courtList;
Court court= new Court();
String[] col= new String[]{
CourtTable.OFFICE_FILE_CODE,
CourtTable.CLIENT_ID,
CourtTable.COURT_DATE
};
SQLiteDatabase sd= getReadableDatabase();
Cursor cur= sd.query(CourtTable.TABLE_NAME, col, null, null, null, null,null);
courtList = new ArrayList<Court>() ;
if(cur!=null && cur.getCount()>0){
cur.moveToFirst();
do{
court.setOfficeFileCode(cur.getInt(cur.getColumnIndex(CourtTable.OFFICE_FILE_CODE)));
court.setClientId(cur.getInt(cur.getColumnIndex(CourtTable.CLIENT_ID)));
court.setCourtDate(cur.getString(cur.getColumnIndex(CourtTable.COURT_DATE)));
courtList.add(court);
}
while(cur.moveToNext());
}
return courtList;
}
Aucun commentaire:
Enregistrer un commentaire