I wanted to do query in table for field id with some vales like 1,5,4,11 which will come from previous screen according to selection.
cursor = database.query
I would like to put this here since a compendium of answers helped me putting multiple (unknown) values in SQLiteDatabase.query() and the one-question-mark did not work for me. Hope helps anyone
// API > 24
protected String attributesAsMarks(String[] attributes) {
List marks = Collections.nCopies(attributes.length, "?");
return marks.stream().collect(Collectors.joining(","));
}
// I'm using API > 15
protected String attributesAsMarks(String[] attributes) {
StringBuilder sb = new StringBuilder();
String separator = "";
for (String s : attributes) {
if (s == null) continue;
sb.append(separator).append("?");
separator = ",";
}
return sb.toString();
}
Thanks to