I have a lot of questions in list callesd `Quesl`. When I write down `Collections.shuffle(Quesl);` list gets randomized, but parts where I have `0` and `R.drawable` for `images` gets randomized on its own, unrelated to other strings in current question, and so I get pictures from unrelated questions on other questions. Is there a way to randomize list without this type of interference?
private static final int DATABASE_VERSION = 1;
// Database Name
private static final String DATABASE_NAME1 = "Bio";
// tasks table name
private static final String TABLE_QUEST1 = "quest";
// tasks Table Columns names
private static final String KEY_ID = "id";
private static final String KEY_QUES = "question1";
private static final String KEY_ANSWER = "answer"; // correct option
private static final String KEY_OPTA = "opta"; // option a
private static final String KEY_OPTB = "optb"; // option b
private static final String KEY_OPTC = "optc"; // option c
private static final String KEY_OPTD = "optd"; // option d
private static final String KEY_OPTE = "opte"; // option e
private SQLiteDatabase dbase1;
public BiologijaPitanja (Context context) {
super(context, DATABASE_NAME1, null, DATABASE_VERSION);
}
@Override
public void onCreate(SQLiteDatabase bio) {
dbase1 = bio;
String sql = "CREATE TABLE IF NOT EXISTS " + TABLE_QUEST1 + " ( "
+ KEY_ID + " INTEGER PRIMARY KEY AUTOINCREMENT, " + KEY_QUES
+ " TEXT, " + KEY_ANSWER + " TEXT, " + KEY_OPTA + " TEXT, "
+ KEY_OPTB + " TEXT, " + KEY_OPTC + " TEXT," + KEY_OPTD
+ " TEXT," + KEY_OPTE + " TEXT)";
bio.execSQL(sql);
addQuestions();
}
private void addQuestions()
{
Question q19 = new Question("Koja je uloga dijela bubrega označenoga na slici slovom F.?",
R.drawable.pit19biojes201314,
"filtracija krvi",
"skupljanje urina",
"dovođenje krvi",
"odvođenje krvi",
"skupljanje urina");
this.addQuestion(q19);
Question q20 = new Question("Koja reakcija prethodi nastanku ureje?",
0,
"razgradnja glukoze",
"deaminacija proteina",
"sinteza pirogrožđane kiseline",
"oksidacija limunske kiseline",
"deaminacija proteina");
this.addQuestion(q20);
}
@Override
public void onUpgrade(SQLiteDatabase bio, int oldV1, int newV1) {
// Drop older table if existed
bio.execSQL("DROP TABLE IF EXISTS " + TABLE_QUEST1);
// Create tables again
onCreate(bio);
}
// Adding new question
public void addQuestion(Question quest1) {
// SQLiteDatabase db = this.getWritableDatabase();
ContentValues values = new ContentValues();
values.put(KEY_QUES, quest1.getQUESTION());
values.put(KEY_ANSWER, quest1.getANSWER());
values.put(KEY_OPTA, quest1.getOPTA());
values.put(KEY_OPTB, quest1.getOPTB());
values.put(KEY_OPTC, quest1.getOPTC());
values.put(KEY_OPTD, quest1.getOPTD());
values.put(KEY_OPTE, quest1.getOPTE());
// Inserting Row
dbase1.insert(TABLE_QUEST1, null, values);
}
public List<Question> getAllQuestions() {
List<Question> quesListBio = new ArrayList<Question>();
String selectQuery1 = "SELECT * FROM " + TABLE_QUEST1;
dbase1 = this.getReadableDatabase();
Cursor cursor = dbase1.rawQuery(selectQuery1, null);
// looping through all rows and adding to list
if (cursor.moveToFirst()) {
do {
Question quest1 = new Question();
quest1.setID(cursor.getInt(0));
quest1.setQUESTION(cursor.getString(1));
quest1.setANSWER(cursor.getString(2));
quest1.setOPTA(cursor.getInt(3));
quest1.setOPTB(cursor.getString(4));
quest1.setOPTC(cursor.getString(5));
quest1.setOPTD(cursor.getString(6));
quest1.setOPTE(cursor.getString(7));
quesListBio.add(quest1);
} while (cursor.moveToNext());
}
// return quest list
return quesListBio;
}
public int rowcount1() {
int row1 = 0;
String selectQuery1 = "SELECT * FROM " + TABLE_QUEST1;
SQLiteDatabase bio = this.getWritableDatabase();
Cursor cursor = bio.rawQuery(selectQuery1, null);
row1 = cursor.getCount();
return row1;
}
}
In main activity there is shuffle method
on crerate blahblah ...
BiologijaPitanja bio=new BiologijaPitanja(this);
quesListBio=bio.getAllQuestions();
Collections.shuffle(quesListBio);
currentQ=quesListBio.get(qid);
我尝试交换0到1,2,3,4,5,6等它不起作用,现在即使我删除shuffle方法它也不会恢复正常状态。在我尝试实现shuffle方法之前,它正常工作