So my question is that, how can I convert a JSONArray to Cursor to use same adapter class?
You can convert that JSONArray
to a MatrixCursor
:
// I'm assuming that the JSONArray will contain only JSONObjects with the same propertties
MatrixCursor mc = new MatrixCursor(new String[] {"columnName1", "columnName2", /* etc*/}); // properties from the JSONObjects
for (int i = 0; i < jsonArray.length(); i++) {
JSONObject jo = jsonArray.getJSONObject(i);
// extract the properties from the JSONObject and use it with the addRow() method below
mc.addRow(new Object[] {property1, property2, /* etc*/});
}