如何在课堂外对此进行响应,以便在应用程序范围内使用?
public void get_Data_home(final TextView tv) {
//URL Builder
String url_home = URL + URL_SERVICES + URL_VERSION + URL_HOME;
final RequestQueue request = Volley.newRequestQueue(this);
JsonObjectRequest postReq = new JsonObjectRequest(Request.Method.GET, url_home, new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
try {
jsonResponse = "";
userAlias = "";
for(int i = 0; i< response.length(); i++) {
String userName = response.getString("loginAlias");
userAlias += "Name: " + userName + "\n\n";
}
tv.setText(jsonResponse);
} catch (JSONException e){
e.printStackTrace();
}
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
System.out.println("Error [" + error + "]");
}
}) {
@Override
public Map getHeaders() throws AuthFailureError {
Map headers = new HashMap();
headers.put("Accept", HEADER_JSON);
System.out.println(headers);
return headers;
}
};
request.add(postReq);
}
这是我需要在app范围内使用的网络。
我曾尝试将网络类导入MainActivity作为测试,但我似乎无法得到响应,以显示为TextView?