I'm new to android development in java and i don't understand one thing. I need to get data from my db (no problem for that) and stock it in a ArrayList of Object but when i put an elem, the next elememt will overwriting all the previous.
public ArrayList<Task> getTaskList(){
SQLiteDatabase db = this.getReadableDatabase();
Cursor cursor = db.query(DB_TABLE,new String[]{DB_TITLE, DB_DESC},null,null,null,null,null);
ArrayList<Task> taskList = new ArrayList<>();
if (taskList == null)
taskList = new ArrayList<>();
while(cursor.moveToNext()){
int indexTitle = cursor.getColumnIndex(DB_TITLE);
int indexDesc = cursor.getColumnIndex(DB_DESC);
String title = cursor.getString(indexTitle);
String desc = cursor.getString(indexDesc);
Task task = new Task(title, desc);
taskList.add(task);
System.out.println("NOTRE LISTE CONTIENT");
for (Task taask : taskList){
System.out.println(taask.getTitle() + "-" + taask.getDescription());
}
}
cursor.close();
db.close();
return taskList;
}
Task.Java
public class Task {
private static String title;
private static String description;
public Task(){}
public Task(String title, String description){
this.title = title;
this.description = description;
System.out.println("NEW TASK: " + title + " " + description);
}
public String getTitle() { return this.title; }
public void setTitle(String title) { this.title = title; }
public String getDescription() { return this.description; }
public void setDescription(String description) { this.description = description; }
}
It's suppose to print:
test-tata potpot-eptept tata-tete test-teeest arr-arg
But print :
arr-arg arr-arg arr-arg arr-arg arr-arg
Do you have any idea? I've shearch but nothing works.. Thanks.