-1

I have a string array and I want to query by where clause with string array.

code

Andy
  • 6,869
  • 2
  • 31
  • 24
booc booc
  • 33
  • 5

1 Answers1

3

You need to build a string of comma separated values from the array, not pass the array.

Assuming

    String[] getAnswerIds = new String[]{"1","4","16","18","20"};
    boolean after_first = false;
    StringBuilder sb = new StringBuilder();
    for (String s: getAnswerIds) {
        if (after_first) {
            sb.append(",");
        } else {
            after_first = true;
        }
        sb.append(s);
    }
    String your_list_of_values = sb.toString();

Then your_list_of_values will be the string 1,4,16,18,20 you then just need to place that string in the appropriate place within the query.

e.g.

    Cursor mycursor = db.rawQuery("SELECT * FROM questions WHERE ID IN(" + your_list_of_values + ")",null);
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
MikeT
  • 51,415
  • 16
  • 49
  • 68