我有这个方法从db:
接收数据public ArrayList<ArrayList<String>> result = new ArrayList<ArrayList<String>>();
public ArrayList<ArrayList<String>> scaricaDatiUtente(){
JsonObjectRequest jsonObjectRequest = new JsonObjectRequest(Request.Method.POST, DatiNet.MostraDati, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
System.out.println(response.toString());
try {
JSONArray utenti = response.getJSONArray("utenti");
for (int i = 0; i < utenti.length(); i++) {
JSONObject student = utenti.getJSONObject(i);
ArrayList<String> studentdata = new ArrayList<String>();
studentdata.add(student.getString("nome"));
studentdata.add(student.getString("cognome"));
studentdata.add(student.getString("numero"));
studentdata.add(student.getString("email"));
result.add(studentdata);
}
} catch (JSONException e) {
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
System.out.append(error.getMessage());
}
});
requestQueue.add(jsonObjectRequest);
return result;
}
问题是在下载数据之前返回结果。 如何让它等待数据然后返回?