My app is a trivia app that i get questions from the database. There are also topics in this app and I thought to implement this by having a column in the database specifically for holding a value that would correspond to what category that the question was. I’ve tried to import a static arraylist of arraylist of boolean values. Then i want to iterate through them to create the array based on if the value is true (my app allows for multiple categories to be able to be picked). The issue is incorporating it (the created arraylist holding topics) into my query statement. I guess the goal is something like -if column two contains these values then add them to the query- I assume this might be child’s play with a direct SQL raw query statement but tbh it looked daunting and so i’ve only ever made myself comfortable with the android alternative.
public Cursor getQuestions() {
List<String> topicsList = new ArrayList<String>(39);
for(int i = 0; i < child_check_states.size(); i++) {
for(int j = 0; j < child_check_states.get(i).size(); j++) {
if (child_check_states.get(i).get(j) == true) {
topicsList.add(i+""+j+"");
}
}
}
Log.d("test", topicsList.toString());
SQLiteDatabase db = getReadableDatabase();
Cursor cursor = db.query(DB_NAME, null, null, null, null, null, "random()");
return cursor;
}
this is off-topic and doesn’t need to be answered, but is there perhaps a peformance issue for randomizing rows like this? I believe that i read once that is better to implement a method that uses two cursors to achieve this. my app only has 4 rows for testing so i haven’t noticed anything, but eventually i’d like to have thousands. maybe tens of thousands.
Just use “IN” keyword, e.g
or, in your example