I am getting 3 different rows from db. When I try to set contents of these rows into the array, I get same values for each index. I am sure that the data is coming from db correctly. But after the loop, it gives me an array whose contents of indexes are same
Here is the code
QuizWord[] words=new QuizWord[4];
words[0]=word; // this "word" object is defined somewhere in the page,don't care
Cursor cursorOther=null;
cursorOther=db.rawQuery("SELECT DISTINCT * FROM words WHERE id NOT IN ('"+trueId+"') ORDER BY RANDOM() LIMIT 3",null);
int i=1;
if(cursorOther.moveToFirst()){
while (cursorOther.moveToNext()) {
QuizWord tempWord = new QuizWord();
tempWord.setId(cursorOther.getInt(0));
tempWord.setTr(cursorOther.getString(1));
tempWord.setEn(cursorOther.getString(3));
tempWord.setAr(cursorOther.getString(2));
tempWord.setGroup_id(Integer.parseInt(cursorOther.getString(4)));
words[i] = tempWord;
Log.v("i-->",String.valueOf(i));
Log.v("current word --_>",tempWord.toString());
i++;
}
cursorOther.close();
}
end of the loop, each indice of array has same object (the last object of the cursor)
Aucun commentaire:
Enregistrer un commentaire