方法监听器

时间:2015-10-12 12:55:44

标签: java android methods

我有这个方法从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;
}

问题是在下载数据之前返回结果。 如何让它等待数据然后返回?

0 个答案:

没有答案