Hello, could anyone help me add an AsyncTask to this task? Here I am connecting to a JSON for information, then it will be added to RecyclerView.
RequestQueue queue = Volley.newRequestQueue(this);
String shhik = "http://meusite/arquivo.json";
StringRequest stringRequest = new StringRequest(Request.Method.GET, shhik, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.d(TAG, "Response " + response);
GsonBuilder builder = new GsonBuilder();
Gson mGson = builder.create();
List<receive_info> posts = new ArrayList<receive_info>();
posts = Arrays.asList(mGson.fromJson(response, receive_info[].class));
adapter = new adapter_info(Main.this, posts);
recyclerView.setAdapter(adapter);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
Toast.makeText(getApplicationContext(), "Erro ao tentar conectar com servidor!", Toast.LENGTH_SHORT).show();
Log.d(TAG, "Error " + error.getMessage());
}
});
queue.add(stringRequest);
}
Thank you!